博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FNV与FNV-1a Hash算法说明【转】
阅读量:6951 次
发布时间:2019-06-27

本文共 3126 字,大约阅读时间需要 10 分钟。

转自:

The core of the FNV hash

The core of the
FNV-1 hash algorithm is as follows:
hash = offset_basisfor each octet_of_data to be hashed hash = hash * FNV_prime hash = hash xor octet_of_datareturn hash

The offset_basis andFNV_prime can be found in the section below.

FNV-1a alternate algorithm

There is a minor variation of the
FNV hash algorithm known as
FNV-1a:
hash = offset_basisfor each octet_of_data to be hashed hash = hash xor octet_of_data hash = hash * FNV_primereturn hash

The only difference between the FNV-1a hash and the FNV-1 hashis the order of the xor and multiply.The FNV-1a hashuses the same FNV_prime and offset_basisas the FNV-1 hash of the same n-bit size.

Parameters of the FNV-1/FNV-1a hash

The
FNV-1 hash parameters are as follows:
  • hash is an n bit unsigned integer,where n is the bit length of hash.
  • The multiplication is performed modulo 2nwhere n is the bit length of hash.
  • The xor is performed on the low orderoctet (8 bits) of hash.
  • The FNV_prime is dependent on n, the size of the hash:
    32 bit
    FNV_prime =2
    24 + 2
    8 + 0x93 =
    16777619
    64 bit
    FNV_prime = 2
    40 + 2
    8 + 0xb3 =
    1099511628211
    128 bit
    FNV_prime = 2
    88 + 2
    8 + 0x3b =
    309485009821345068724781371
    256 bit
    FNV_prime = 2
    168 + 2
    8 + 0x63 =
    374144419156711147060143317175368453031918731002211
    512 bit
    FNV_prime = 2
    344 + 2
    8 + 0x57 =
    35835915874844867368919076489095108449946327955754392558399825615420669938882575
    126094039892345713852759
    1024 bit
    FNV_prime = 2
    680 + 2
    8 + 0x8d =
    50164565101131186554345988110352789550307653454047907443030175238311120551081474
    51509157692220295382716162651878526895249385292291816524375083746691371804094271
    873160484737966720260389217684476157468082573

    Part of the magic of FNV is the selection of the FNV_primefor a given sized unsigned integer.Some primes do hash better than other primes for a given integer size.

  • The offset_basis for FNV-1 is dependent on n, the size of the hash:
    32 bit
    offset_basis =
    2166136261
    64 bit
    offset_basis =
    14695981039346656037
    128 bit
    offset_basis =
    144066263297769815596495629667062367629
    256 bit
    offset_basis =
    100029257958052580907070968620625704837092796014241193945225284501741471925557
    512 bit
    offset_basis =
    96593031294966694980094354007163104660904187456726378961083743294344626579945829
    32197716438449813051892206539805784495328239340083876191928701583869517785
    1024 bit
    offset_basis =
    14197795064947621068722070641403218320880622795441933960878474914617582723252296
    73230371772215086409652120235554936562817466910857181476047101507614802975596980
    40773201576924585630032153049571501574036444603635505054127112859663616102678680
    82893823963790439336411086884584107735010676915

    NOTE: Older versions of this web page incorretly indicated that the 128 bitFNV_prime was 2168 + 28 + 0x59.This was not correct.While that satisfied all of the significant FNV_prime properties,it was not the smallest 128 bit FNV_prime.The 128 bit offset_basischanged from275519064689413815358837431229664493455to144066263297769815596495629667062367629was changed as a result of the 128 bit FNV_prime correction.(Sorry about that!)

转载于:https://www.cnblogs.com/sky-heaven/p/6478167.html

你可能感兴趣的文章
加快城镇化建设 完成智慧城市规划
查看>>
上海多所高校均新设“数据科学与大数据技术”专业
查看>>
Ovum:运营商在云服务中渐入佳境 未来前景乐观
查看>>
Salesforce不仅要当SaaS巨头,它还想在VC行业干一番大事业
查看>>
开源博客-秋色园QBlog多用户博客系统安装视频教程
查看>>
数据中心可能的威胁是污染
查看>>
如何在Ubuntu服务器安装openDCIM简化数据中心管理
查看>>
IDC:2015年第四季度全球WLAN市场增幅最高
查看>>
在Linux环境下使用TCP的keepalive机制
查看>>
什么才是真正的大数据征信?
查看>>
Getting started with Kotlin on Android
查看>>
这是网络安全的基石:密码学2016大盘点
查看>>
大数据:食品安全的“补天石”
查看>>
D1net阅闻:Facebook上线求职功能,以挑战LinedIn
查看>>
天津市多措并举有序推进农业物联网标准体系建设
查看>>
webrtc 支持h264 思路
查看>>
异地多活没那么难
查看>>
FB上市五周年:北美经济损失上万亿美元
查看>>
《STM32库开发实战指南:基于STM32F103(第2版)》——第1章如何安装KEIL5
查看>>
《R语言机器学习:实用案例分析》——1.4节控制代码流
查看>>