hmac_link.c revision 431a83fb29482c5170b3e4026e59bb14849a6707
b7b6b01a0d0622181a4c28dd60401f0ab2480d00Mark Andrews * Portions Copyright (C) 2004-2014 Internet Systems Consortium, Inc. ("ISC")
fcb54ce0a4f7377486df5bec83b3aa4711bf4131Mark Andrews * Portions Copyright (C) 1999-2002 Internet Software Consortium.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * 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 AND NETWORK ASSOCIATES DISCLAIMS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * Portions Copyright (C) 1995-2000 by Network Associates, Inc.
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence * Permission to use, copy, modify, and/or distribute this software for any
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * purpose with or without fee is hereby granted, provided that the above
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * copyright notice and this permission notice appear in all copies.
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
8cdfd17426179ae6f629a9b7475d46a22f535047Bob Halley * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
294802790e8030f1c19b6c2c5d5204b6f464c729Michael Graff * Principal Author: Brian Wellington
9282e3c21a20f354e22ad3f092aea4956abaea5cMichael Graff * $Id: hmac_link.c,v 1.19 2011/01/11 23:47:13 tbox Exp $
d1cbf714097e900ed1703529584d3e1a50e8a4a8Brian Wellingtonstatic isc_result_t hmacmd5_fromdns(dst_key_t *key, isc_buffer_t *data);
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graffgetkeybits(dst_key_t *key, struct dst_private_element *element) {
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence key->key_bits = (element->data[0] << 8) + element->data[1];
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graffhmacmd5_createctx(dst_key_t *key, dst_context_t *dctx) {
8cdfd17426179ae6f629a9b7475d46a22f535047Bob Halley hmacmd5ctx = isc_mem_get(dctx->mctx, sizeof(isc_hmacmd5_t));
3115cd89bc1e1fd3ecc4705d253e3484a3f5c555Michael Graff isc_hmacmd5_init(hmacmd5ctx, hkey->key, ISC_SHA1_BLOCK_LENGTH);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_hmacmd5_t *hmacmd5ctx = dctx->ctxdata.hmacmd5ctx;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_mem_put(dctx->mctx, hmacmd5ctx, sizeof(isc_hmacmd5_t));
7b5172166d816efabcdb22519b136ba124bb2619Brian Wellingtonhmacmd5_adddata(dst_context_t *dctx, const isc_region_t *data) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_hmacmd5_t *hmacmd5ctx = dctx->ctxdata.hmacmd5ctx;
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff isc_hmacmd5_update(hmacmd5ctx, data->base, data->length);
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graffhmacmd5_sign(dst_context_t *dctx, isc_buffer_t *sig) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_hmacmd5_t *hmacmd5ctx = dctx->ctxdata.hmacmd5ctx;
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrews unsigned char *digest;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff if (isc_buffer_availablelength(sig) < ISC_MD5_DIGESTLENGTH)
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graffhmacmd5_verify(dst_context_t *dctx, const isc_region_t *sig) {
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff isc_hmacmd5_t *hmacmd5ctx = dctx->ctxdata.hmacmd5ctx;
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff if (isc_hmacmd5_verify2(hmacmd5ctx, sig->base, sig->length))
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graffhmacmd5_compare(const dst_key_t *key1, const dst_key_t *key2) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA1_BLOCK_LENGTH))
6dde125c2f47617ceef1518cf9e5588e8f366b71Michael Graffhmacmd5_generate(dst_key_t *key, int pseudorandom_ok, void (*callback)(int)) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein unsigned int bytes;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein ret = dst__entropy_getdata(data, bytes, ISC_TF(pseudorandom_ok != 0));
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff isc_mem_put(key->mctx, hkey, sizeof(dst_hmacmd5_key_t));
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graffhmacmd5_todns(const dst_key_t *key, isc_buffer_t *data) {
306a93530536f05edfb477cac1c2667d90129a8fMichael Graff unsigned int bytes;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graffhmacmd5_fromdns(dst_key_t *key, isc_buffer_t *data) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein hkey = isc_mem_get(key->mctx, sizeof(dst_hmacmd5_key_t));
439c0011e642fb1d26011116144af698125262dbMichael Graffhmacmd5_tofile(const dst_key_t *key, const char *directory) {
784d78b831830bf7b53507e742254f9c49295752Andreas Gustafsson priv.elements[cnt].tag = TAG_HMACMD5_KEY;
439c0011e642fb1d26011116144af698125262dbMichael Graff return (dst__privstruct_writefile(key, &priv, directory));
f36a81c88493985ee2d1c53cc6fe88f4b00dbbc8Michael Graffhmacmd5_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) {
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graff unsigned int i;
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff /* read private key file */
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff result = dst__privstruct_parse(key, DST_ALG_HMACMD5, lexer, mctx,
439c0011e642fb1d26011116144af698125262dbMichael Graff for (i = 0; i < priv.nelements && result == ISC_R_SUCCESS; i++) {
14b98cb34eda66c87ce41a207704a2c232280eafMichael Graffstatic isc_result_t hmacsha1_fromdns(dst_key_t *key, isc_buffer_t *data);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graffhmacsha1_createctx(dst_key_t *key, dst_context_t *dctx) {
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff dst_hmacsha1_key_t *hkey = key->keydata.hmacsha1;
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff hmacsha1ctx = isc_mem_get(dctx->mctx, sizeof(isc_hmacsha1_t));
49a940dc68b30d9e4f9e1bd3c0503d8b90bb1726Mark Andrews isc_hmacsha1_init(hmacsha1ctx, hkey->key, ISC_SHA1_BLOCK_LENGTH);
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graff isc_hmacsha1_t *hmacsha1ctx = dctx->ctxdata.hmacsha1ctx;
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff isc_mem_put(dctx->mctx, hmacsha1ctx, sizeof(isc_hmacsha1_t));
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graffhmacsha1_adddata(dst_context_t *dctx, const isc_region_t *data) {
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff isc_hmacsha1_t *hmacsha1ctx = dctx->ctxdata.hmacsha1ctx;
ffd9f879709c5fb35f25368e74e2e12eb6881d9bMichael Graff isc_hmacsha1_update(hmacsha1ctx, data->base, data->length);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graffhmacsha1_sign(dst_context_t *dctx, isc_buffer_t *sig) {
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff isc_hmacsha1_t *hmacsha1ctx = dctx->ctxdata.hmacsha1ctx;
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff unsigned char *digest;
3d12fa7e76c02d06e1adeaa7846b60378a3cd204Michael Graff if (isc_buffer_availablelength(sig) < ISC_SHA1_DIGESTLENGTH)
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff isc_hmacsha1_sign(hmacsha1ctx, digest, ISC_SHA1_DIGESTLENGTH);
53cf67186506f9557aaf2149898dd76715803db2Mark Andrewshmacsha1_verify(dst_context_t *dctx, const isc_region_t *sig) {
53cf67186506f9557aaf2149898dd76715803db2Mark Andrews isc_hmacsha1_t *hmacsha1ctx = dctx->ctxdata.hmacsha1ctx;
550085fed1d0af54ba5b2f588898afec158195deMark Andrews if (sig->length > ISC_SHA1_DIGESTLENGTH || sig->length == 0)
550085fed1d0af54ba5b2f588898afec158195deMark Andrews if (isc_hmacsha1_verify(hmacsha1ctx, sig->base, sig->length))
306a93530536f05edfb477cac1c2667d90129a8fMichael Graffhmacsha1_compare(const dst_key_t *key1, const dst_key_t *key2) {
306a93530536f05edfb477cac1c2667d90129a8fMichael Graff if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA1_BLOCK_LENGTH))
306a93530536f05edfb477cac1c2667d90129a8fMichael Graffhmacsha1_generate(dst_key_t *key, int pseudorandom_ok, void (*callback)(int)) {
9e992ecf375cd1eaa5351d06eca8cf7f543d5938Andreas Gustafsson unsigned char data[ISC_SHA1_BLOCK_LENGTH];
306a93530536f05edfb477cac1c2667d90129a8fMichael Graff ret = dst__entropy_getdata(data, bytes, ISC_TF(pseudorandom_ok != 0));
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff dst_hmacsha1_key_t *hkey = key->keydata.hmacsha1;
a14eb88840e06b8d458c1556e5452b6d2a50012eMichael Graff isc_mem_put(key->mctx, hkey, sizeof(dst_hmacsha1_key_t));
a14eb88840e06b8d458c1556e5452b6d2a50012eMichael Graffhmacsha1_todns(const dst_key_t *key, isc_buffer_t *data) {
a14eb88840e06b8d458c1556e5452b6d2a50012eMichael Graff unsigned int bytes;
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graffhmacsha1_fromdns(dst_key_t *key, isc_buffer_t *data) {
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff hkey = isc_mem_get(key->mctx, sizeof(dst_hmacsha1_key_t));
d1fb73ada84ee15ea078c80b1cd0ca8ddc6aa856Michael Graffhmacsha1_tofile(const dst_key_t *key, const char *directory) {
528829aa8ad69238e674cd81078bc14d4199691bMichael Graff return (dst__privstruct_writefile(key, &priv, directory));
528829aa8ad69238e674cd81078bc14d4199691bMichael Graffhmacsha1_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) {
6bd8cee98332533a4fa705b82ca9ec1606738ba9Mark Andrews unsigned int i;
6bd8cee98332533a4fa705b82ca9ec1606738ba9Mark Andrews /* read private key file */
6bd8cee98332533a4fa705b82ca9ec1606738ba9Mark Andrews result = dst__privstruct_parse(key, DST_ALG_HMACSHA1, lexer, mctx,
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graffstatic isc_result_t hmacsha224_fromdns(dst_key_t *key, isc_buffer_t *data);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graffhmacsha224_createctx(dst_key_t *key, dst_context_t *dctx) {
78854e02c127f31ab90f56da0531542004b45377Michael Graff dst_hmacsha224_key_t *hkey = key->keydata.hmacsha224;
7ec42e4be45c0486ce80461293f377fb4b904dc0Michael Graff hmacsha224ctx = isc_mem_get(dctx->mctx, sizeof(isc_hmacsha224_t));
7ec42e4be45c0486ce80461293f377fb4b904dc0Michael Graff isc_hmacsha224_init(hmacsha224ctx, hkey->key, ISC_SHA224_BLOCK_LENGTH);
7ec42e4be45c0486ce80461293f377fb4b904dc0Michael Graff isc_hmacsha224_t *hmacsha224ctx = dctx->ctxdata.hmacsha224ctx;
7ec42e4be45c0486ce80461293f377fb4b904dc0Michael Graff isc_mem_put(dctx->mctx, hmacsha224ctx, sizeof(isc_hmacsha224_t));
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffhmacsha224_adddata(dst_context_t *dctx, const isc_region_t *data) {
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff isc_hmacsha224_t *hmacsha224ctx = dctx->ctxdata.hmacsha224ctx;
7ec42e4be45c0486ce80461293f377fb4b904dc0Michael Graff isc_hmacsha224_update(hmacsha224ctx, data->base, data->length);
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffhmacsha224_sign(dst_context_t *dctx, isc_buffer_t *sig) {
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff isc_hmacsha224_t *hmacsha224ctx = dctx->ctxdata.hmacsha224ctx;
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graff unsigned char *digest;
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff if (isc_buffer_availablelength(sig) < ISC_SHA224_DIGESTLENGTH)
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff isc_hmacsha224_sign(hmacsha224ctx, digest, ISC_SHA224_DIGESTLENGTH);
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffhmacsha224_verify(dst_context_t *dctx, const isc_region_t *sig) {
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrews isc_hmacsha224_t *hmacsha224ctx = dctx->ctxdata.hmacsha224ctx;
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrews if (sig->length > ISC_SHA224_DIGESTLENGTH || sig->length == 0)
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graff if (isc_hmacsha224_verify(hmacsha224ctx, sig->base, sig->length))
081cff0c33514a5dc63ab794fc199c07377ab756Mark Andrewshmacsha224_compare(const dst_key_t *key1, const dst_key_t *key2) {
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA224_BLOCK_LENGTH))
93d3a6fd20aceb9998eca4723bba8810243e7689Michael Graffhmacsha224_generate(dst_key_t *key, int pseudorandom_ok,
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff unsigned int bytes;
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graff ret = dst__entropy_getdata(data, bytes, ISC_TF(pseudorandom_ok != 0));
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff dst_hmacsha224_key_t *hkey = key->keydata.hmacsha224;
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff memset(hkey, 0, sizeof(dst_hmacsha224_key_t));
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff isc_mem_put(key->mctx, hkey, sizeof(dst_hmacsha224_key_t));
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graffhmacsha224_todns(const dst_key_t *key, isc_buffer_t *data) {
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff unsigned int bytes;
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halleyhmacsha224_fromdns(dst_key_t *key, isc_buffer_t *data) {
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halley hkey = isc_mem_get(key->mctx, sizeof(dst_hmacsha224_key_t));
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graffhmacsha224_tofile(const dst_key_t *key, const char *directory) {
45dadd25ba4b72ec2d8eecc342edc787d8421e3aBob Halley return (dst__privstruct_writefile(key, &priv, directory));
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffhmacsha224_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) {
45dadd25ba4b72ec2d8eecc342edc787d8421e3aBob Halley unsigned int i;
45dadd25ba4b72ec2d8eecc342edc787d8421e3aBob Halley /* read private key file */
45dadd25ba4b72ec2d8eecc342edc787d8421e3aBob Halley result = dst__privstruct_parse(key, DST_ALG_HMACSHA224, lexer, mctx,
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graffstatic isc_result_t hmacsha256_fromdns(dst_key_t *key, isc_buffer_t *data);
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graffhmacsha256_createctx(dst_key_t *key, dst_context_t *dctx) {
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff dst_hmacsha256_key_t *hkey = key->keydata.hmacsha256;
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff hmacsha256ctx = isc_mem_get(dctx->mctx, sizeof(isc_hmacsha256_t));
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff isc_hmacsha256_init(hmacsha256ctx, hkey->key, ISC_SHA256_BLOCK_LENGTH);
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff isc_hmacsha256_t *hmacsha256ctx = dctx->ctxdata.hmacsha256ctx;
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff isc_mem_put(dctx->mctx, hmacsha256ctx, sizeof(isc_hmacsha256_t));
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graffhmacsha256_adddata(dst_context_t *dctx, const isc_region_t *data) {
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff isc_hmacsha256_t *hmacsha256ctx = dctx->ctxdata.hmacsha256ctx;
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff isc_hmacsha256_update(hmacsha256ctx, data->base, data->length);
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graffhmacsha256_sign(dst_context_t *dctx, isc_buffer_t *sig) {
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff isc_hmacsha256_t *hmacsha256ctx = dctx->ctxdata.hmacsha256ctx;
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff unsigned char *digest;
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff if (isc_buffer_availablelength(sig) < ISC_SHA256_DIGESTLENGTH)
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff isc_hmacsha256_sign(hmacsha256ctx, digest, ISC_SHA256_DIGESTLENGTH);
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffhmacsha256_verify(dst_context_t *dctx, const isc_region_t *sig) {
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff isc_hmacsha256_t *hmacsha256ctx = dctx->ctxdata.hmacsha256ctx;
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halley if (sig->length > ISC_SHA256_DIGESTLENGTH || sig->length == 0)
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halley if (isc_hmacsha256_verify(hmacsha256ctx, sig->base, sig->length))
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halleyhmacsha256_compare(const dst_key_t *key1, const dst_key_t *key2) {
4abed3e3563c7ad346178433130e6d150d3ffeafBob Halley if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA256_BLOCK_LENGTH))
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halleyhmacsha256_generate(dst_key_t *key, int pseudorandom_ok,
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halley void (*callback)(int))
d1cbf714097e900ed1703529584d3e1a50e8a4a8Brian Wellington unsigned char data[ISC_SHA256_BLOCK_LENGTH];
d1cbf714097e900ed1703529584d3e1a50e8a4a8Brian Wellington key->key_size = ISC_SHA256_BLOCK_LENGTH * 8;
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halley ret = dst__entropy_getdata(data, bytes, ISC_TF(pseudorandom_ok != 0));
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halley dst_hmacsha256_key_t *hkey = key->keydata.hmacsha256;
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halley isc_mem_put(key->mctx, hkey, sizeof(dst_hmacsha256_key_t));
16508d9185e5eb96af2ebe900a08c46a6e5eb7edBob Halleyhmacsha256_todns(const dst_key_t *key, isc_buffer_t *data) {
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff unsigned int bytes;
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graffhmacsha256_fromdns(dst_key_t *key, isc_buffer_t *data) {
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff hkey = isc_mem_get(key->mctx, sizeof(dst_hmacsha256_key_t));
78854e02c127f31ab90f56da0531542004b45377Michael Graff isc_sha256_update(&sha256ctx, r.base, r.length);
78854e02c127f31ab90f56da0531542004b45377Michael Graffhmacsha256_tofile(const dst_key_t *key, const char *directory) {
78854e02c127f31ab90f56da0531542004b45377Michael Graff return (dst__privstruct_writefile(key, &priv, directory));
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graffhmacsha256_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) {
306a93530536f05edfb477cac1c2667d90129a8fMichael Graff unsigned int i;
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff /* read private key file */
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff result = dst__privstruct_parse(key, DST_ALG_HMACSHA256, lexer, mctx,
a385f150bb21b8b81f70ed7df545357a83f1da82Michael Graffstatic isc_result_t hmacsha384_fromdns(dst_key_t *key, isc_buffer_t *data);
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graffhmacsha384_createctx(dst_key_t *key, dst_context_t *dctx) {
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff dst_hmacsha384_key_t *hkey = key->keydata.hmacsha384;
78bf1ca89505820ed7b03be4bf0c0b53b557f3cdAndreas Gustafsson hmacsha384ctx = isc_mem_get(dctx->mctx, sizeof(isc_hmacsha384_t));
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff isc_hmacsha384_init(hmacsha384ctx, hkey->key, ISC_SHA384_BLOCK_LENGTH);
439c0011e642fb1d26011116144af698125262dbMichael Graff isc_hmacsha384_t *hmacsha384ctx = dctx->ctxdata.hmacsha384ctx;
439c0011e642fb1d26011116144af698125262dbMichael Graff isc_mem_put(dctx->mctx, hmacsha384ctx, sizeof(isc_hmacsha384_t));
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffhmacsha384_adddata(dst_context_t *dctx, const isc_region_t *data) {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_hmacsha384_t *hmacsha384ctx = dctx->ctxdata.hmacsha384ctx;
439c0011e642fb1d26011116144af698125262dbMichael Graff isc_hmacsha384_update(hmacsha384ctx, data->base, data->length);
439c0011e642fb1d26011116144af698125262dbMichael Graffhmacsha384_sign(dst_context_t *dctx, isc_buffer_t *sig) {
439c0011e642fb1d26011116144af698125262dbMichael Graff isc_hmacsha384_t *hmacsha384ctx = dctx->ctxdata.hmacsha384ctx;
439c0011e642fb1d26011116144af698125262dbMichael Graff unsigned char *digest;
439c0011e642fb1d26011116144af698125262dbMichael Graff if (isc_buffer_availablelength(sig) < ISC_SHA384_DIGESTLENGTH)
4abed3e3563c7ad346178433130e6d150d3ffeafBob Halley isc_hmacsha384_sign(hmacsha384ctx, digest, ISC_SHA384_DIGESTLENGTH);
439c0011e642fb1d26011116144af698125262dbMichael Graffhmacsha384_verify(dst_context_t *dctx, const isc_region_t *sig) {
439c0011e642fb1d26011116144af698125262dbMichael Graff isc_hmacsha384_t *hmacsha384ctx = dctx->ctxdata.hmacsha384ctx;
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graff if (sig->length > ISC_SHA384_DIGESTLENGTH || sig->length == 0)
439c0011e642fb1d26011116144af698125262dbMichael Graff if (isc_hmacsha384_verify(hmacsha384ctx, sig->base, sig->length))
439c0011e642fb1d26011116144af698125262dbMichael Graffhmacsha384_compare(const dst_key_t *key1, const dst_key_t *key2) {
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA384_BLOCK_LENGTH))
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graffhmacsha384_generate(dst_key_t *key, int pseudorandom_ok,
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff unsigned int bytes;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff ret = dst__entropy_getdata(data, bytes, ISC_TF(pseudorandom_ok != 0));
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff dst_hmacsha384_key_t *hkey = key->keydata.hmacsha384;
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff memset(hkey, 0, sizeof(dst_hmacsha384_key_t));
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_mem_put(key->mctx, hkey, sizeof(dst_hmacsha384_key_t));
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graffhmacsha384_todns(const dst_key_t *key, isc_buffer_t *data) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff unsigned int bytes;
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graffhmacsha384_fromdns(dst_key_t *key, isc_buffer_t *data) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff hkey = isc_mem_get(key->mctx, sizeof(dst_hmacsha384_key_t));
f36a81c88493985ee2d1c53cc6fe88f4b00dbbc8Michael Graff isc_sha384_update(&sha384ctx, r.base, r.length);
439c0011e642fb1d26011116144af698125262dbMichael Graffhmacsha384_tofile(const dst_key_t *key, const char *directory) {
439c0011e642fb1d26011116144af698125262dbMichael Graff return (dst__privstruct_writefile(key, &priv, directory));
a44c12b332b867f29631e235eb11d1263c73d6c0Bob Halleyhmacsha384_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff unsigned int i;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /* read private key file */
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff result = dst__privstruct_parse(key, DST_ALG_HMACSHA384, lexer, mctx,
e34efaccfaab4dbbe45edd0a58e2b6e930e5784bMichael Graffstatic isc_result_t hmacsha512_fromdns(dst_key_t *key, isc_buffer_t *data);
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graffhmacsha512_createctx(dst_key_t *key, dst_context_t *dctx) {
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff dst_hmacsha512_key_t *hkey = key->keydata.hmacsha512;
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff hmacsha512ctx = isc_mem_get(dctx->mctx, sizeof(isc_hmacsha512_t));
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff isc_hmacsha512_init(hmacsha512ctx, hkey->key, ISC_SHA512_BLOCK_LENGTH);
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff isc_hmacsha512_t *hmacsha512ctx = dctx->ctxdata.hmacsha512ctx;
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff isc_mem_put(dctx->mctx, hmacsha512ctx, sizeof(isc_hmacsha512_t));
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graffhmacsha512_adddata(dst_context_t *dctx, const isc_region_t *data) {
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff isc_hmacsha512_t *hmacsha512ctx = dctx->ctxdata.hmacsha512ctx;
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff isc_hmacsha512_update(hmacsha512ctx, data->base, data->length);
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graffhmacsha512_sign(dst_context_t *dctx, isc_buffer_t *sig) {
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff isc_hmacsha512_t *hmacsha512ctx = dctx->ctxdata.hmacsha512ctx;
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff unsigned char *digest;
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff if (isc_buffer_availablelength(sig) < ISC_SHA512_DIGESTLENGTH)
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff isc_hmacsha512_sign(hmacsha512ctx, digest, ISC_SHA512_DIGESTLENGTH);
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graffhmacsha512_verify(dst_context_t *dctx, const isc_region_t *sig) {
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff isc_hmacsha512_t *hmacsha512ctx = dctx->ctxdata.hmacsha512ctx;
5a5b79c5ab0ccdc821dd5498935e5cc7b96d2499Michael Graff if (sig->length > ISC_SHA512_DIGESTLENGTH || sig->length == 0)
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff if (isc_hmacsha512_verify(hmacsha512ctx, sig->base, sig->length))
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graffhmacsha512_compare(const dst_key_t *key1, const dst_key_t *key2) {
439c0011e642fb1d26011116144af698125262dbMichael Graff if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA512_BLOCK_LENGTH))
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graffhmacsha512_generate(dst_key_t *key, int pseudorandom_ok,
d98c74e2ec5b96bd22aa4ed6d893e8993787493bMichael Graff unsigned int bytes;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff ret = dst__entropy_getdata(data, bytes, ISC_TF(pseudorandom_ok != 0));
6d14fe95e9ea5bbc5e863e5aab4618f7b3dbcc0fMichael Graff dst_hmacsha512_key_t *hkey = key->keydata.hmacsha512;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff memset(hkey, 0, sizeof(dst_hmacsha512_key_t));
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff isc_mem_put(key->mctx, hkey, sizeof(dst_hmacsha512_key_t));
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graffhmacsha512_todns(const dst_key_t *key, isc_buffer_t *data) {
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff unsigned int bytes;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graffhmacsha512_fromdns(dst_key_t *key, isc_buffer_t *data) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff hkey = isc_mem_get(key->mctx, sizeof(dst_hmacsha512_key_t));
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff isc_sha512_update(&sha512ctx, r.base, r.length);
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graffhmacsha512_tofile(const dst_key_t *key, const char *directory) {
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff return (dst__privstruct_writefile(key, &priv, directory));
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graffhmacsha512_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) {
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff unsigned int i;
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff /* read private key file */