diff --git a/hmac-sha384.c b/hmac-sha384.c new file mode 100644 index 0000000000000000000000000000000000000000..f39705f5d3ae94488e9b58d46a6e67d8ea95c34d --- /dev/null +++ b/hmac-sha384.c @@ -0,0 +1,44 @@ +/* hmac-sha384.c + * + * HMAC-SHA384 message authentication code. + */ + +/* nettle, low-level cryptographics library + * + * Copyright (C) 2003, 2010 Niels M�ller + * + * The nettle library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * The nettle library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the nettle library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "hmac.h" + +void +hmac_sha384_set_key(struct hmac_sha512_ctx *ctx, + unsigned key_length, const uint8_t *key) +{ + HMAC_SET_KEY(ctx, &nettle_sha384, key_length, key); +} + +void +hmac_sha384_digest(struct hmac_sha512_ctx *ctx, + unsigned length, uint8_t *digest) +{ + HMAC_DIGEST(ctx, &nettle_sha384, length, digest); +} diff --git a/hmac.h b/hmac.h index 8a3b1631f6b9eb03e7a63902c171896f63b17813..a413de7548be9153b80440d6c4671ad34479a63d 100644 --- a/hmac.h +++ b/hmac.h @@ -144,6 +144,19 @@ void hmac_sha512_digest(struct hmac_sha512_ctx *ctx, unsigned length, uint8_t *digest); +/* hmac-sha384 */ +#define hmac_sha384_ctx hmac_sha512_ctx + +void +hmac_sha384_set_key(struct hmac_sha512_ctx *ctx, + unsigned key_length, const uint8_t *key); + +#define hmac_sha384_update hmac_sha512_update + +void +hmac_sha384_digest(struct hmac_sha512_ctx *ctx, + unsigned length, uint8_t *digest); + #ifdef __cplusplus } #endif diff --git a/testsuite/sha224-test.c b/testsuite/sha224-test.c new file mode 100644 index 0000000000000000000000000000000000000000..cef82affac0d381fea17e744253af38140003bd1 --- /dev/null +++ b/testsuite/sha224-test.c @@ -0,0 +1,48 @@ +#include "testutils.h" +#include "sha.h" + +int +test_main(void) +{ + /* From FIPS180-2 addendum + (http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf) */ + test_hash(&nettle_sha224, 3, "abc", + H("23097d22 3405d822 8642a477 bda255b3" + "2aadbce4 bda0b3f7 e36c9da7")); + + test_hash(&nettle_sha224, 56, + "abcdbcdecdefdefgefghfghighij" + "hijkijkljklmklmnlmnomnopnopq", + H("75388b16 512776cc 5dba5da1 fd890150" + "b0c6455c b4f58b19 52522525")); + + /* Additional test vectors, from Daniel Kahn Gillmor */ + test_hash(&nettle_sha224, LDATA(""), + H("d14a028c2a3a2bc9 476102bb288234c4" + "15a2b01f828ea62a c5b3e42f")); + test_hash(&nettle_sha224, LDATA("a"), + H("abd37534c7d9a2ef b9465de931cd7055" + "ffdb8879563ae980 78d6d6d5")); + test_hash(&nettle_sha224, LDATA("38"), + H("4cfca6da32da6471 98225460722b7ea1" + "284f98c4b179e8db ae3f93d5")); + test_hash(&nettle_sha224, LDATA("message digest"), + H("2cb21c83ae2f004d e7e81c3c7019cbcb" + "65b71ab656b22d6d 0c39b8eb")); + test_hash(&nettle_sha224, LDATA("abcdefghijklmnopqrstuvwxyz"), + H("45a5f72c39c5cff2 522eb3429799e49e" + "5f44b356ef926bcf 390dccc2")); + test_hash(&nettle_sha224, + LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef" + "ghijklmnopqrstuvwxyz0123456789"), + H("bff72b4fcb7d75e5 632900ac5f90d219" + "e05e97a7bde72e74 0db393d9")); + test_hash(&nettle_sha224, + LDATA("12345678901234567890123456789012" + "34567890123456789012345678901234" + "5678901234567890"), + H("b50aecbe4e9bb0b5 7bc5f3ae760a8e01" + "db24f203fb3cdcd1 3148046e")); + + SUCCESS(); +}