基于散列消息验证码的一次性密码算法

基于HMAC的一次性密码算法(英語:HMAC-based One-time Password algorithm,HOTP)是一种基于散列消息验证码(HMAC)的一次性密码(OTP)算法,同时也是开放验证提案的基础(OATH)。

HOTP在2005年由IETF发布在RFC 4226标准文档中,定义了算法的同时附带有一例基于Java的实现。自此之后,世界上许多公司接纳了HOTP算法,它也成为了可以自由使用的开源标准

算法 编辑

HOTP算法在验证时使用对称生成的人类可读密码(算法中也称为“运算值”),每个密码仅在一次验证中有效。这种一次性属性直接来自于计数器数值的单次使用。

任何有意愿使用HOTP的一方都必须定义一系列对于验证器而言已明确的参数,无论是否这些参数是否可以被验证器接受,都可能包含:

  • 加密散列算法,记为H(默认为SHA-1
  • 服务器分发的密钥,记为K,可以是任意长度的字符串,但必须保密。
  • HOTP运算值长度,记为d,(数值从6至10均可,默认为6,建议为6至8)

HOTP验证中的双方都会运算最终数值,验证器会将本地运算结果与被验证方提供的结果进行比对。

由于验证双方都分别各自自增计数器数值,验证器的计数器可能落后于被验证方,因此定义用于重新同步的协议是意义的。RFC 4226标准中给出了相关建议,但并不做强制要求。为解决可能的不同步,验证器会使用当前计数器值起尝试用连续多个值(称为窗口)进行运算,如果验证成功,则验证器将对应的计数器值更新为当前值,无需被验证方做任何操作。窗口大小由参数指定。[1]:7,8

上述建议是出于避免HOTP数值验证过程中出现卡死,但是同时也使得数值相对偏小,暴力破解攻击也因此变得容易。有一个建议是在验证失败几次之后就锁定验证过程,或者每次验证失败时都(以线性方式)延长下次操作时间。

专有的硬件密钥通常会提供六位验证码,也就是d的默认值。密钥截留最长长度为31位,由于公式中   ≈ 9.3,也就是d的最大值取10,因此第十位数值可能的取值也就更少,为0、1或者2(也就对应多出的0.3这个小数数值)。

双重重定向验证 编辑

在验证之后,验证器可以通过运算得出下一个HOTP数值来执行验算,得出返回的数值之后,接受验证的一方将计算HOTP数值进行验证。值得注意的是,这一过程中的计数器数值需要保证同步。

HOTP运算值 编辑

HOTP运算值设计上是人类可读的,它是一个位数为d的十进制数字(开头的0不可忽略):

HOTP运算值 = HOTP(K, C) mod 10d

上述公式也说明运算值是最小位数为d的十进制数值。

HOTP本质上是散列消息验证码(HMAC)的计数器截留,计数器数值记为C(服务器分发密钥记为K,散列函数记为H)。

HOTP(K, C) = truncate(HMACH(K, C))

截取首先是位于最小的四位MAC数值当中,截得之后用于作为回调数值,记为i

truncate(MAC) = extract31(MAC, MAC[(19 × 8) + 4:(19 × 8) + 7] × 8)

引索数值i用于从MAC当中选中31位数,起始点为i + 1

extract31(MAC, i) = MAC[i + 1:i + (4 × 8) − 1]

注意,取得的31位数长度仅有单位值的4字节,可以容纳于4字节短语意味着没有标记位。这是出于避免负数的模数运算,但是这也有许多不同的定义与实现。[2]

密钥 编辑

已有许多供应商(参考下面的列举)提供软件以及硬件密钥。实现开放验证提案的HOTP硬件密钥实现往往比使用专有算法的同类产品便宜许多。[3] 截止至2010年,这些硬件密钥的价格已经很低。[4] 有些产品也可以同时用于生成强密码。[5]

软件密钥在(几乎)所有主要移动平台或智能手机均有提供(如J2ME,[6] Android,[7][8] iPhone,[9] BlackBerry,[10] Maemo,[11] macOS,[12] 以及Windows Mobile[10])。

接纳程度 编辑

尽管许多计算机媒体在2004-05年持负面态度,[13][14][15]自从IETF在2005年十二月将HOTP接纳为RFC 4226标准之后,许多提供商开始生产兼容HOTP的密钥,甚至是基于此的整套验证解决方案。

2010年伯顿集团英语Burton Group高德纳咨询公司的下辖部门)发表文章,表示“高德纳咨询公司预期基于硬件的一次性密码封装的市场会有一定程度的增长,对于智能手机来说,一次性密码将会成为默认硬件平台的一部分”。[3]

另请参阅 编辑

参考资料 编辑

  1. ^ RFC 4226 - HOTP: An HMAC-Based One-Time Password Algorithm. IETF. 2005-12 [2019-03-18]. (原始内容存档于2019-04-06) (英语). 
  2. ^ Frank, Hoornaert. HOTP: An HMAC-Based One-Time Password Algorithm. tools.ietf.org. [2019-03-18]. (原始内容存档于2019-04-06). 
  3. ^ 3.0 3.1 Diodati, Mark. Road Map: Replacing Passwords with OTP Authentication. Burton Group. 2010 [2019-03-18]. (原始内容存档于2011-07-21). Gartner's expectation is that the hardware OTP form factor will continue to enjoy modest growth while smartphone OTPs will grow and become the default hardware platform over time. ... If the organization does not need the extensive platform support, then OATH-based technology is likely a more cost-effective choice. 
  4. ^ Security Authentication Tokens - Entrust. Entrust. 2011 [2019-03-18]. (原始内容存档于2013-04-05). Priced at $5 per token, the Entrust IdentityGuard Mini Token demonstrates that secure, reliable hardware authentication can be had at an attractive price. ... OATH and DES/3DES algorithm support 
  5. ^ Password sCrib Tokens - Smart Crib. Smart Crib. 2013 [2019-03-18]. (原始内容存档于2013-09-04). You can get a token typing 4 updatable passwords and 8 digit OATH HOTP codes for the price of £35, no strings attached. 
  6. ^ DS3 Launches OathToken Midlet Application. Data Security Systems Solutions. 2006-02-24 [2019-03-18]. (原始内容存档于2013-12-29). Singapore, Friday, 24 February 2006 - Data Security Systems Solutions is pleased to announce the launch of OathToken Midlet application, an extension of DS3 flagship product - Authentication Server. 
  7. ^ Android Token. diamondz... AT googlemail.com (not a full address, no better info on author could be found). 2009 [2019-03-18]. (原始内容存档于2011-10-16). Android Token is a project to create OATH software tokens for the Android platform. Turning a mobile phone into a One Time Password (OTP) generation device which can be used in the place of hardware tokens. ... The project supports both HOTP (Event Tokens) and TOTP (Time Tokens) specifications. ... Code license: GNU GPL v3 
  8. ^ StrongAuth. StrongAuth. 2010 [2019-03-18]. (原始内容存档于2010-05-18). Time-based one-time passcode generator based on HOTP (RFC 4226). 
  9. ^ Cobbs, Archie L. OATH Token. Archie L. Cobbs. 2010 [2019-03-18]. (原始内容存档于2011-08-22). OATH Token is a free and open-source software token for two-factor authentication on the iPhone. OATH Token implements the RFC 4226 HOTP/OATH algorithm standard and is not tied to any proprietary server software. 
  10. ^ 10.0 10.1 ActivIdentity Soft Tokens. ActivIdentity. 2010 [2019-03-18]. (原始内容存档于2010-09-17). All ActivIdentity Soft Tokens support the Initiative For Open Authentication (OATH) HMAC-Based One-Time Password (HOTP) algorithm. ... ActivIdentity Mobile Soft Tokens are available on leading handset operating systems, including BlackBerry®, Apple® iPhone®, Windows Mobile, and many other Java 2 Platform, Micro Edition (J2ME) enabled devices. 
  11. ^ Whitbeck, Sean. OTP Generator for N900. Sean Whitbeck. 2011 [2019-03-18]. (原始内容存档于2020-08-23). OTP Generator for Maemo on the Nokia N900. Supports OATH tokens (HOTP,TOTP) as well as the Mobile-OTP algorithm. 
  12. ^ SecuriToken. Feel Good Software. 2011 [2019-03-18]. (原始内容存档于2012-04-25). SecuriToken is an RFC compliant application to create and manage multiple software tokens for the OS X platform. Turning your Mac into a One Time Password (OTP) generation device which can be used in the place of hardware tokens. 
  13. ^ Kearns, Dave. Digging deeper into OATH doesn't look so good. Network World. 2004-12-06 [2019-03-18]. (原始内容存档于2012-10-14). It may be that OATH will amount to something someday, but so far, it appears to be a stalking horse for VeriSign and that's not a bandwagon we should thoughtlessly jump on. 
  14. ^ Willoughby, Mark. No agreement on Oath authentication. Computerworld. 2005-03-21 [2019-03-18]. (原始内容存档于2012-10-11). 
  15. ^ Kaliski, Burt. Algorithm agility and OATH. Computerworld. 2005-05-19 [2019-03-18]. (原始内容存档于2012-10-11). Nevertheless, there is still good reason to question whether HOTP is suitable as a standard algorithm for OTP generation, and, more generally, whether such a standard algorithm is even necessary at all. 

外部链接 编辑