ac2d0e2004-02-02Martin Nilsson 
dc93732015-08-22Martin Nilsson //! HMAC, defined by @rfc{2104@}.
ac2d0e2004-02-02Martin Nilsson  #pike __REAL_VERSION__
59bfa12005-01-23Martin Nilsson #pragma strict_types
e1fb092014-02-14Martin Nilsson #require constant(Crypto.Hash)
9e47712004-02-29Martin Nilsson 
9eaf1d2008-06-28Martin Nilsson protected .Hash H; // hash object
ac2d0e2004-02-02Martin Nilsson  // B is the size of one compression block, in octets.
9eaf1d2008-06-28Martin Nilsson protected int B;
ac2d0e2004-02-02Martin Nilsson  //! @param h //! The hash object on which the HMAC object should base its //! operations. Typical input is @[Crypto.MD5]. //! @param b //! The block size of one compression block, in octets. Defaults to
793fc02013-11-30Martin Nilsson //! block_size() of @[h]. protected void create(.Hash h, int|void b)
ac2d0e2004-02-02Martin Nilsson { H = h;
793fc02013-11-30Martin Nilsson  B = b || H->block_size();
ac2d0e2004-02-02Martin Nilsson  if(H->digest_size()>B) error("Block size is less than hash digest size.\n"); } //! Calls the hash function given to @[create] and returns the hash //! value of @[s].
387ff92013-12-19Martin Nilsson string(8bit) raw_hash(string(8bit) s)
ac2d0e2004-02-02Martin Nilsson { return H->hash(s); } //! Makes a PKCS-1 digestinfo block with the message @[s]. //! @seealso //! @[Standards.PKCS.Signature.build_digestinfo]
387ff92013-12-19Martin Nilsson string(8bit) pkcs_digest(string(8bit) s)
ac2d0e2004-02-02Martin Nilsson { return Standards.PKCS.Signature.build_digestinfo(s, H); } //! Calling the HMAC object with a password returns a new object that //! can perform the actual HMAC hashing. E.g. doing a HMAC hash with //! MD5 and the password @expr{"bar"@} of the string @expr{"foo"@} //! would require the code @expr{Crypto.HMAC(Crypto.MD5)("bar")("foo")@}.
28271a2014-04-25Henrik Grubbström (Grubba) Crypto.MAC.State `()(string(8bit) passwd)
ac2d0e2004-02-02Martin Nilsson {
272ef22013-12-20Martin Nilsson  return H->HMAC(passwd, B);
ac2d0e2004-02-02Martin Nilsson }