hmacmd5.c revision 5b7abbef511cea0b568be0bc8d5b3120a0b9034d
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Copyright (C) 2004-2007, 2009 Internet Systems Consortium, Inc. ("ISC")
fcb54ce0a4f7377486df5bec83b3aa4711bf4131Mark Andrews * Copyright (C) 2000, 2001 Internet Software Consortium.
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * Permission to use, copy, modify, and/or distribute this software for any
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * purpose with or without fee is hereby granted, provided that the above
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * copyright notice and this permission notice appear in all copies.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
a95a9de45ca739dab17ec1263186dbaaaba50d97Tatuya JINMEI 神明達哉/* $Id: hmacmd5.c,v 1.16 2009/02/06 23:47:42 tbox Exp $ */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * This code implements the HMAC-MD5 keyed hash algorithm
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * described in RFC2104.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrenceisc_hmacmd5_init(isc_hmacmd5_t *ctx, const unsigned char *key,
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff unsigned int len)
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff HMAC_Init(ctx, (const void *) key, (int) len, EVP_md5());
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graffisc_hmacmd5_update(isc_hmacmd5_t *ctx, const unsigned char *buf,
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff unsigned int len)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graffisc_hmacmd5_sign(isc_hmacmd5_t *ctx, unsigned char *digest) {
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * Start HMAC-MD5 process. Initialize an md5 context and digest the key.
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graffisc_hmacmd5_init(isc_hmacmd5_t *ctx, const unsigned char *key,
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff unsigned int len)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff for (i = 0; i < PADLEN; i++)
7b5172166d816efabcdb22519b136ba124bb2619Brian Wellington isc_md5_update(&ctx->md5ctx, ipad, sizeof(ipad));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * Update context to reflect the concatenation of another buffer full
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graffisc_hmacmd5_update(isc_hmacmd5_t *ctx, const unsigned char *buf,
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff unsigned int len)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * Compute signature - finalize MD5 operation and reapply MD5.
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrewsisc_hmacmd5_sign(isc_hmacmd5_t *ctx, unsigned char *digest) {
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley for (i = 0; i < PADLEN; i++)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_md5_update(&ctx->md5ctx, opad, sizeof(opad));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff isc_md5_update(&ctx->md5ctx, digest, ISC_MD5_DIGESTLENGTH);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater#endif /* !ISC_PLATFORM_OPENSSLHASH */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Verify signature - finalize MD5 operation and reapply MD5, then
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * compare to the supplied digest.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updaterisc_hmacmd5_verify(isc_hmacmd5_t *ctx, unsigned char *digest) {
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff return (isc_hmacmd5_verify2(ctx, digest, ISC_MD5_DIGESTLENGTH));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updaterisc_hmacmd5_verify2(isc_hmacmd5_t *ctx, unsigned char *digest, size_t len) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater unsigned char newdigest[ISC_MD5_DIGESTLENGTH];