Lines Matching refs:ctx
36 #define HMAC_CTX_new() &(ctx->_ctx), HMAC_CTX_init(&(ctx->_ctx))
41 isc_hmacsha1_init(isc_hmacsha1_t *ctx, const unsigned char *key,
44 ctx->ctx = HMAC_CTX_new();
45 RUNTIME_CHECK(ctx->ctx != NULL);
46 RUNTIME_CHECK(HMAC_Init_ex(ctx->ctx, (const void *) key,
51 isc_hmacsha1_invalidate(isc_hmacsha1_t *ctx) {
52 if (ctx->ctx == NULL)
54 HMAC_CTX_free(ctx->ctx);
55 ctx->ctx = NULL;
59 isc_hmacsha1_update(isc_hmacsha1_t *ctx, const unsigned char *buf,
62 RUNTIME_CHECK(HMAC_Update(ctx->ctx, buf, (int) len) == 1);
66 isc_hmacsha1_sign(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len) {
71 RUNTIME_CHECK(HMAC_Final(ctx->ctx, newdigest, NULL) == 1);
72 HMAC_CTX_free(ctx->ctx);
73 ctx->ctx = NULL;
79 isc_hmacsha224_init(isc_hmacsha224_t *ctx, const unsigned char *key,
82 ctx->ctx = HMAC_CTX_new();
83 RUNTIME_CHECK(ctx->ctx != NULL);
84 RUNTIME_CHECK(HMAC_Init_ex(ctx->ctx, (const void *) key,
89 isc_hmacsha224_invalidate(isc_hmacsha224_t *ctx) {
90 if (ctx->ctx == NULL)
92 HMAC_CTX_free(ctx->ctx);
93 ctx->ctx = NULL;
97 isc_hmacsha224_update(isc_hmacsha224_t *ctx, const unsigned char *buf,
100 RUNTIME_CHECK(HMAC_Update(ctx->ctx, buf, (int) len) == 1);
104 isc_hmacsha224_sign(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len) {
109 RUNTIME_CHECK(HMAC_Final(ctx->ctx, newdigest, NULL) == 1);
110 HMAC_CTX_free(ctx->ctx);
111 ctx->ctx = NULL;
117 isc_hmacsha256_init(isc_hmacsha256_t *ctx, const unsigned char *key,
120 ctx->ctx = HMAC_CTX_new();
121 RUNTIME_CHECK(ctx->ctx != NULL);
122 RUNTIME_CHECK(HMAC_Init_ex(ctx->ctx, (const void *) key,
127 isc_hmacsha256_invalidate(isc_hmacsha256_t *ctx) {
128 if (ctx->ctx == NULL)
130 HMAC_CTX_free(ctx->ctx);
131 ctx->ctx = NULL;
135 isc_hmacsha256_update(isc_hmacsha256_t *ctx, const unsigned char *buf,
138 RUNTIME_CHECK(HMAC_Update(ctx->ctx, buf, (int) len) == 1);
142 isc_hmacsha256_sign(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len) {
147 RUNTIME_CHECK(HMAC_Final(ctx->ctx, newdigest, NULL) == 1);
148 HMAC_CTX_free(ctx->ctx);
149 ctx->ctx = NULL;
155 isc_hmacsha384_init(isc_hmacsha384_t *ctx, const unsigned char *key,
158 ctx->ctx = HMAC_CTX_new();
159 RUNTIME_CHECK(ctx->ctx != NULL);
160 RUNTIME_CHECK(HMAC_Init_ex(ctx->ctx, (const void *) key,
165 isc_hmacsha384_invalidate(isc_hmacsha384_t *ctx) {
166 if (ctx->ctx == NULL)
168 HMAC_CTX_free(ctx->ctx);
169 ctx->ctx = NULL;
173 isc_hmacsha384_update(isc_hmacsha384_t *ctx, const unsigned char *buf,
176 RUNTIME_CHECK(HMAC_Update(ctx->ctx, buf, (int) len) == 1);
180 isc_hmacsha384_sign(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len) {
185 RUNTIME_CHECK(HMAC_Final(ctx->ctx, newdigest, NULL) == 1);
186 HMAC_CTX_free(ctx->ctx);
187 ctx->ctx = NULL;
193 isc_hmacsha512_init(isc_hmacsha512_t *ctx, const unsigned char *key,
196 ctx->ctx = HMAC_CTX_new();
197 RUNTIME_CHECK(ctx->ctx != NULL);
198 RUNTIME_CHECK(HMAC_Init_ex(ctx->ctx, (const void *) key,
203 isc_hmacsha512_invalidate(isc_hmacsha512_t *ctx) {
204 if (ctx->ctx == NULL)
206 HMAC_CTX_free(ctx->ctx);
207 ctx->ctx = NULL;
211 isc_hmacsha512_update(isc_hmacsha512_t *ctx, const unsigned char *buf,
214 RUNTIME_CHECK(HMAC_Update(ctx->ctx, buf, (int) len) == 1);
218 isc_hmacsha512_sign(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len) {
223 RUNTIME_CHECK(HMAC_Final(ctx->ctx, newdigest, NULL) == 1);
224 HMAC_CTX_free(ctx->ctx);
225 ctx->ctx = NULL;
252 isc_hmacsha1_init(isc_hmacsha1_t *ctx, const unsigned char *key,
281 RUNTIME_CHECK(pk11_get_session(ctx, OP_DIGEST, ISC_TRUE, ISC_FALSE,
283 ctx->object = CK_INVALID_HANDLE;
285 (ctx->session, keyTemplate,
286 (CK_ULONG) 6, &ctx->object));
287 INSIST(ctx->object != CK_INVALID_HANDLE);
288 PK11_FATALCHECK(pkcs_C_SignInit, (ctx->session, &mech, ctx->object));
292 isc_hmacsha1_invalidate(isc_hmacsha1_t *ctx) {
296 if (ctx->handle == NULL)
298 (void) pkcs_C_SignFinal(ctx->session, garbage, &len);
300 if (ctx->object != CK_INVALID_HANDLE)
301 (void) pkcs_C_DestroyObject(ctx->session, ctx->object);
302 ctx->object = CK_INVALID_HANDLE;
303 pk11_return_session(ctx);
307 isc_hmacsha1_update(isc_hmacsha1_t *ctx, const unsigned char *buf,
315 (ctx->session, pPart, (CK_ULONG) len));
319 isc_hmacsha1_sign(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len) {
326 PK11_FATALCHECK(pkcs_C_SignFinal, (ctx->session, newdigest, &psl));
327 if (ctx->object != CK_INVALID_HANDLE)
328 (void) pkcs_C_DestroyObject(ctx->session, ctx->object);
329 ctx->object = CK_INVALID_HANDLE;
330 pk11_return_session(ctx);
336 isc_hmacsha1_init(isc_hmacsha1_t *ctx, const unsigned char *key,
344 RUNTIME_CHECK(pk11_get_session(ctx, OP_DIGEST, ISC_TRUE, ISC_FALSE,
346 RUNTIME_CHECK((ctx->key = pk11_mem_get(ISC_SHA1_BLOCK_LENGTH))
352 PK11_FATALCHECK(pkcs_C_DigestInit, (ctx->session, &mech));
355 (ctx->session, kPart, (CK_ULONG) len));
358 (ctx->session, (CK_BYTE_PTR) ctx->key, &kl));
360 memmove(ctx->key, key, len);
361 PK11_FATALCHECK(pkcs_C_DigestInit, (ctx->session, &mech));
364 ipad[i] ^= ctx->key[i];
366 (ctx->session, ipad,
371 isc_hmacsha1_invalidate(isc_hmacsha1_t *ctx) {
372 if (ctx->key != NULL)
373 pk11_mem_put(ctx->key, ISC_SHA1_BLOCK_LENGTH);
374 ctx->key = NULL;
375 isc_sha1_invalidate(ctx);
379 isc_hmacsha1_update(isc_hmacsha1_t *ctx, const unsigned char *buf,
387 (ctx->session, pPart, (CK_ULONG) len));
391 isc_hmacsha1_sign(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len) {
401 PK11_FATALCHECK(pkcs_C_DigestFinal, (ctx->session, newdigest, &psl));
404 opad[i] ^= ctx->key[i];
405 pk11_mem_put(ctx->key, ISC_SHA1_BLOCK_LENGTH);
406 ctx->key = NULL;
407 PK11_FATALCHECK(pkcs_C_DigestInit, (ctx->session, &mech));
409 (ctx->session, opad,
412 (ctx->session, (CK_BYTE_PTR) newdigest, psl));
413 PK11_FATALCHECK(pkcs_C_DigestFinal, (ctx->session, newdigest, &psl));
414 pk11_return_session(ctx);
422 isc_hmacsha224_init(isc_hmacsha224_t *ctx, const unsigned char *key,
451 RUNTIME_CHECK(pk11_get_session(ctx, OP_DIGEST, ISC_TRUE, ISC_FALSE,
453 ctx->object = CK_INVALID_HANDLE;
455 (ctx->session, keyTemplate,
456 (CK_ULONG) 6, &ctx->object));
457 INSIST(ctx->object != CK_INVALID_HANDLE);
458 PK11_FATALCHECK(pkcs_C_SignInit, (ctx->session, &mech, ctx->object));
462 isc_hmacsha224_invalidate(isc_hmacsha224_t *ctx) {
466 if (ctx->handle == NULL)
468 (void) pkcs_C_SignFinal(ctx->session, garbage, &len);
470 if (ctx->object != CK_INVALID_HANDLE)
471 (void) pkcs_C_DestroyObject(ctx->session, ctx->object);
472 ctx->object = CK_INVALID_HANDLE;
473 pk11_return_session(ctx);
477 isc_hmacsha224_update(isc_hmacsha224_t *ctx, const unsigned char *buf,
485 (ctx->session, pPart, (CK_ULONG) len));
489 isc_hmacsha224_sign(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len) {
496 PK11_FATALCHECK(pkcs_C_SignFinal, (ctx->session, newdigest, &psl));
497 if (ctx->object != CK_INVALID_HANDLE)
498 (void) pkcs_C_DestroyObject(ctx->session, ctx->object);
499 ctx->object = CK_INVALID_HANDLE;
500 pk11_return_session(ctx);
506 isc_hmacsha224_init(isc_hmacsha224_t *ctx, const unsigned char *key,
514 RUNTIME_CHECK(pk11_get_session(ctx, OP_DIGEST, ISC_TRUE, ISC_FALSE,
516 RUNTIME_CHECK((ctx->key = pk11_mem_get(ISC_SHA224_BLOCK_LENGTH))
522 PK11_FATALCHECK(pkcs_C_DigestInit, (ctx->session, &mech));
525 (ctx->session, kPart, (CK_ULONG) len));
528 (ctx->session, (CK_BYTE_PTR) ctx->key, &kl));
530 memmove(ctx->key, key, len);
531 PK11_FATALCHECK(pkcs_C_DigestInit, (ctx->session, &mech));
534 ipad[i] ^= ctx->key[i];
536 (ctx->session, ipad,
541 isc_hmacsha224_invalidate(isc_hmacsha224_t *ctx) {
542 if (ctx->key != NULL)
543 pk11_mem_put(ctx->key, ISC_SHA224_BLOCK_LENGTH);
544 ctx->key = NULL;
545 isc_sha224_invalidate(ctx);
549 isc_hmacsha224_update(isc_hmacsha224_t *ctx, const unsigned char *buf,
557 (ctx->session, pPart, (CK_ULONG) len));
561 isc_hmacsha224_sign(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len) {
571 PK11_FATALCHECK(pkcs_C_DigestFinal, (ctx->session, newdigest, &psl));
574 opad[i] ^= ctx->key[i];
575 pk11_mem_put(ctx->key, ISC_SHA224_BLOCK_LENGTH);
576 ctx->key = NULL;
577 PK11_FATALCHECK(pkcs_C_DigestInit, (ctx->session, &mech));
579 (ctx->session, opad,
582 (ctx->session, (CK_BYTE_PTR) newdigest, psl));
583 PK11_FATALCHECK(pkcs_C_DigestFinal, (ctx->session, newdigest, &psl));
584 pk11_return_session(ctx);
592 isc_hmacsha256_init(isc_hmacsha256_t *ctx, const unsigned char *key,
621 RUNTIME_CHECK(pk11_get_session(ctx, OP_DIGEST, ISC_TRUE, ISC_FALSE,
623 ctx->object = CK_INVALID_HANDLE;
625 (ctx->session, keyTemplate,
626 (CK_ULONG) 6, &ctx->object));
627 INSIST(ctx->object != CK_INVALID_HANDLE);
628 PK11_FATALCHECK(pkcs_C_SignInit, (ctx->session, &mech, ctx->object));
632 isc_hmacsha256_invalidate(isc_hmacsha256_t *ctx) {
636 if (ctx->handle == NULL)
638 (void) pkcs_C_SignFinal(ctx->session, garbage, &len);
640 if (ctx->object != CK_INVALID_HANDLE)
641 (void) pkcs_C_DestroyObject(ctx->session, ctx->object);
642 ctx->object = CK_INVALID_HANDLE;
643 pk11_return_session(ctx);
647 isc_hmacsha256_update(isc_hmacsha256_t *ctx, const unsigned char *buf,
655 (ctx->session, pPart, (CK_ULONG) len));
659 isc_hmacsha256_sign(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len) {
666 PK11_FATALCHECK(pkcs_C_SignFinal, (ctx->session, newdigest, &psl));
667 if (ctx->object != CK_INVALID_HANDLE)
668 (void) pkcs_C_DestroyObject(ctx->session, ctx->object);
669 ctx->object = CK_INVALID_HANDLE;
670 pk11_return_session(ctx);
676 isc_hmacsha256_init(isc_hmacsha256_t *ctx, const unsigned char *key,
684 RUNTIME_CHECK(pk11_get_session(ctx, OP_DIGEST, ISC_TRUE, ISC_FALSE,
686 RUNTIME_CHECK((ctx->key = pk11_mem_get(ISC_SHA256_BLOCK_LENGTH))
692 PK11_FATALCHECK(pkcs_C_DigestInit, (ctx->session, &mech));
695 (ctx->session, kPart, (CK_ULONG) len));
698 (ctx->session, (CK_BYTE_PTR) ctx->key, &kl));
700 memmove(ctx->key, key, len);
701 PK11_FATALCHECK(pkcs_C_DigestInit, (ctx->session, &mech));
704 ipad[i] ^= ctx->key[i];
706 (ctx->session, ipad,
711 isc_hmacsha256_invalidate(isc_hmacsha256_t *ctx) {
712 if (ctx->key != NULL)
713 pk11_mem_put(ctx->key, ISC_SHA256_BLOCK_LENGTH);
714 ctx->key = NULL;
715 isc_sha256_invalidate(ctx);
719 isc_hmacsha256_update(isc_hmacsha256_t *ctx, const unsigned char *buf,
727 (ctx->session, pPart, (CK_ULONG) len));
731 isc_hmacsha256_sign(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len) {
741 PK11_FATALCHECK(pkcs_C_DigestFinal, (ctx->session, newdigest, &psl));
744 opad[i] ^= ctx->key[i];
745 pk11_mem_put(ctx->key, ISC_SHA256_BLOCK_LENGTH);
746 ctx->key = NULL;
747 PK11_FATALCHECK(pkcs_C_DigestInit, (ctx->session, &mech));
749 (ctx->session, opad,
752 (ctx->session, (CK_BYTE_PTR) newdigest, psl));
753 PK11_FATALCHECK(pkcs_C_DigestFinal, (ctx->session, newdigest, &psl));
754 pk11_return_session(ctx);
762 isc_hmacsha384_init(isc_hmacsha384_t *ctx, const unsigned char *key,
791 RUNTIME_CHECK(pk11_get_session(ctx, OP_DIGEST, ISC_TRUE, ISC_FALSE,
793 ctx->object = CK_INVALID_HANDLE;
795 (ctx->session, keyTemplate,
796 (CK_ULONG) 6, &ctx->object));
797 INSIST(ctx->object != CK_INVALID_HANDLE);
798 PK11_FATALCHECK(pkcs_C_SignInit, (ctx->session, &mech, ctx->object));
802 isc_hmacsha384_invalidate(isc_hmacsha384_t *ctx) {
806 if (ctx->handle == NULL)
808 (void) pkcs_C_SignFinal(ctx->session, garbage, &len);
810 if (ctx->object != CK_INVALID_HANDLE)
811 (void) pkcs_C_DestroyObject(ctx->session, ctx->object);
812 ctx->object = CK_INVALID_HANDLE;
813 pk11_return_session(ctx);
817 isc_hmacsha384_update(isc_hmacsha384_t *ctx, const unsigned char *buf,
825 (ctx->session, pPart, (CK_ULONG) len));
829 isc_hmacsha384_sign(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len) {
836 PK11_FATALCHECK(pkcs_C_SignFinal, (ctx->session, newdigest, &psl));
837 if (ctx->object != CK_INVALID_HANDLE)
838 (void) pkcs_C_DestroyObject(ctx->session, ctx->object);
839 ctx->object = CK_INVALID_HANDLE;
840 pk11_return_session(ctx);
846 isc_hmacsha384_init(isc_hmacsha384_t *ctx, const unsigned char *key,
854 RUNTIME_CHECK(pk11_get_session(ctx, OP_DIGEST, ISC_TRUE, ISC_FALSE,
856 RUNTIME_CHECK((ctx->key = pk11_mem_get(ISC_SHA384_BLOCK_LENGTH))
862 PK11_FATALCHECK(pkcs_C_DigestInit, (ctx->session, &mech));
865 (ctx->session, kPart, (CK_ULONG) len));
868 (ctx->session, (CK_BYTE_PTR) ctx->key, &kl));
870 memmove(ctx->key, key, len);
871 PK11_FATALCHECK(pkcs_C_DigestInit, (ctx->session, &mech));
874 ipad[i] ^= ctx->key[i];
876 (ctx->session, ipad,
881 isc_hmacsha384_invalidate(isc_hmacsha384_t *ctx) {
882 if (ctx->key != NULL)
883 pk11_mem_put(ctx->key, ISC_SHA384_BLOCK_LENGTH);
884 ctx->key = NULL;
885 isc_sha384_invalidate(ctx);
889 isc_hmacsha384_update(isc_hmacsha384_t *ctx, const unsigned char *buf,
897 (ctx->session, pPart, (CK_ULONG) len));
901 isc_hmacsha384_sign(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len) {
911 PK11_FATALCHECK(pkcs_C_DigestFinal, (ctx->session, newdigest, &psl));
914 opad[i] ^= ctx->key[i];
915 pk11_mem_put(ctx->key, ISC_SHA384_BLOCK_LENGTH);
916 ctx->key = NULL;
917 PK11_FATALCHECK(pkcs_C_DigestInit, (ctx->session, &mech));
919 (ctx->session, opad,
922 (ctx->session, (CK_BYTE_PTR) newdigest, psl));
923 PK11_FATALCHECK(pkcs_C_DigestFinal, (ctx->session, newdigest, &psl));
924 pk11_return_session(ctx);
932 isc_hmacsha512_init(isc_hmacsha512_t *ctx, const unsigned char *key,
961 RUNTIME_CHECK(pk11_get_session(ctx, OP_DIGEST, ISC_TRUE, ISC_FALSE,
963 ctx->object = CK_INVALID_HANDLE;
965 (ctx->session, keyTemplate,
966 (CK_ULONG) 6, &ctx->object));
967 INSIST(ctx->object != CK_INVALID_HANDLE);
968 PK11_FATALCHECK(pkcs_C_SignInit, (ctx->session, &mech, ctx->object));
972 isc_hmacsha512_invalidate(isc_hmacsha512_t *ctx) {
976 if (ctx->handle == NULL)
978 (void) pkcs_C_SignFinal(ctx->session, garbage, &len);
980 if (ctx->object != CK_INVALID_HANDLE)
981 (void) pkcs_C_DestroyObject(ctx->session, ctx->object);
982 ctx->object = CK_INVALID_HANDLE;
983 pk11_return_session(ctx);
987 isc_hmacsha512_update(isc_hmacsha512_t *ctx, const unsigned char *buf,
995 (ctx->session, pPart, (CK_ULONG) len));
999 isc_hmacsha512_sign(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len) {
1006 PK11_FATALCHECK(pkcs_C_SignFinal, (ctx->session, newdigest, &psl));
1007 if (ctx->object != CK_INVALID_HANDLE)
1008 (void) pkcs_C_DestroyObject(ctx->session, ctx->object);
1009 ctx->object = CK_INVALID_HANDLE;
1010 pk11_return_session(ctx);
1016 isc_hmacsha512_init(isc_hmacsha512_t *ctx, const unsigned char *key,
1024 RUNTIME_CHECK(pk11_get_session(ctx, OP_DIGEST, ISC_TRUE, ISC_FALSE,
1026 RUNTIME_CHECK((ctx->key = pk11_mem_get(ISC_SHA512_BLOCK_LENGTH))
1032 PK11_FATALCHECK(pkcs_C_DigestInit, (ctx->session, &mech));
1035 (ctx->session, kPart, (CK_ULONG) len));
1038 (ctx->session, (CK_BYTE_PTR) ctx->key, &kl));
1040 memmove(ctx->key, key, len);
1041 PK11_FATALCHECK(pkcs_C_DigestInit, (ctx->session, &mech));
1044 ipad[i] ^= ctx->key[i];
1046 (ctx->session, ipad,
1051 isc_hmacsha512_invalidate(isc_hmacsha512_t *ctx) {
1052 if (ctx->key != NULL)
1053 pk11_mem_put(ctx->key, ISC_SHA512_BLOCK_LENGTH);
1054 ctx->key = NULL;
1055 isc_sha512_invalidate(ctx);
1059 isc_hmacsha512_update(isc_hmacsha512_t *ctx, const unsigned char *buf,
1067 (ctx->session, pPart, (CK_ULONG) len));
1071 isc_hmacsha512_sign(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len) {
1081 PK11_FATALCHECK(pkcs_C_DigestFinal, (ctx->session, newdigest, &psl));
1084 opad[i] ^= ctx->key[i];
1085 pk11_mem_put(ctx->key, ISC_SHA512_BLOCK_LENGTH);
1086 ctx->key = NULL;
1087 PK11_FATALCHECK(pkcs_C_DigestInit, (ctx->session, &mech));
1089 (ctx->session, opad,
1092 (ctx->session, (CK_BYTE_PTR) newdigest, psl));
1093 PK11_FATALCHECK(pkcs_C_DigestFinal, (ctx->session, newdigest, &psl));
1094 pk11_return_session(ctx);
1109 isc_hmacsha1_init(isc_hmacsha1_t *ctx, const unsigned char *key,
1115 memset(ctx->key, 0, sizeof(ctx->key));
1116 if (len > sizeof(ctx->key)) {
1120 isc_sha1_final(&sha1ctx, ctx->key);
1122 memmove(ctx->key, key, len);
1124 isc_sha1_init(&ctx->sha1ctx);
1127 ipad[i] ^= ctx->key[i];
1128 isc_sha1_update(&ctx->sha1ctx, ipad, sizeof(ipad));
1132 isc_hmacsha1_invalidate(isc_hmacsha1_t *ctx) {
1133 isc_sha1_invalidate(&ctx->sha1ctx);
1134 isc_safe_memwipe(ctx, sizeof(*ctx));
1142 isc_hmacsha1_update(isc_hmacsha1_t *ctx, const unsigned char *buf,
1145 isc_sha1_update(&ctx->sha1ctx, buf, len);
1152 isc_hmacsha1_sign(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len) {
1158 isc_sha1_final(&ctx->sha1ctx, newdigest);
1162 opad[i] ^= ctx->key[i];
1164 isc_sha1_init(&ctx->sha1ctx);
1165 isc_sha1_update(&ctx->sha1ctx, opad, sizeof(opad));
1166 isc_sha1_update(&ctx->sha1ctx, newdigest, ISC_SHA1_DIGESTLENGTH);
1167 isc_sha1_final(&ctx->sha1ctx, newdigest);
1168 isc_hmacsha1_invalidate(ctx);
1177 isc_hmacsha224_init(isc_hmacsha224_t *ctx, const unsigned char *key,
1183 memset(ctx->key, 0, sizeof(ctx->key));
1184 if (len > sizeof(ctx->key)) {
1188 isc_sha224_final(ctx->key, &sha224ctx);
1190 memmove(ctx->key, key, len);
1192 isc_sha224_init(&ctx->sha224ctx);
1195 ipad[i] ^= ctx->key[i];
1196 isc_sha224_update(&ctx->sha224ctx, ipad, sizeof(ipad));
1200 isc_hmacsha224_invalidate(isc_hmacsha224_t *ctx) {
1201 isc_safe_memwipe(ctx, sizeof(*ctx));
1209 isc_hmacsha224_update(isc_hmacsha224_t *ctx, const unsigned char *buf,
1212 isc_sha224_update(&ctx->sha224ctx, buf, len);
1219 isc_hmacsha224_sign(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len) {
1225 isc_sha224_final(newdigest, &ctx->sha224ctx);
1229 opad[i] ^= ctx->key[i];
1231 isc_sha224_init(&ctx->sha224ctx);
1232 isc_sha224_update(&ctx->sha224ctx, opad, sizeof(opad));
1233 isc_sha224_update(&ctx->sha224ctx, newdigest, ISC_SHA224_DIGESTLENGTH);
1234 isc_sha224_final(newdigest, &ctx->sha224ctx);
1243 isc_hmacsha256_init(isc_hmacsha256_t *ctx, const unsigned char *key,
1249 memset(ctx->key, 0, sizeof(ctx->key));
1250 if (len > sizeof(ctx->key)) {
1254 isc_sha256_final(ctx->key, &sha256ctx);
1256 memmove(ctx->key, key, len);
1258 isc_sha256_init(&ctx->sha256ctx);
1261 ipad[i] ^= ctx->key[i];
1262 isc_sha256_update(&ctx->sha256ctx, ipad, sizeof(ipad));
1266 isc_hmacsha256_invalidate(isc_hmacsha256_t *ctx) {
1267 isc_safe_memwipe(ctx, sizeof(*ctx));
1275 isc_hmacsha256_update(isc_hmacsha256_t *ctx, const unsigned char *buf,
1278 isc_sha256_update(&ctx->sha256ctx, buf, len);
1285 isc_hmacsha256_sign(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len) {
1291 isc_sha256_final(newdigest, &ctx->sha256ctx);
1295 opad[i] ^= ctx->key[i];
1297 isc_sha256_init(&ctx->sha256ctx);
1298 isc_sha256_update(&ctx->sha256ctx, opad, sizeof(opad));
1299 isc_sha256_update(&ctx->sha256ctx, newdigest, ISC_SHA256_DIGESTLENGTH);
1300 isc_sha256_final(newdigest, &ctx->sha256ctx);
1309 isc_hmacsha384_init(isc_hmacsha384_t *ctx, const unsigned char *key,
1315 memset(ctx->key, 0, sizeof(ctx->key));
1316 if (len > sizeof(ctx->key)) {
1320 isc_sha384_final(ctx->key, &sha384ctx);
1322 memmove(ctx->key, key, len);
1324 isc_sha384_init(&ctx->sha384ctx);
1327 ipad[i] ^= ctx->key[i];
1328 isc_sha384_update(&ctx->sha384ctx, ipad, sizeof(ipad));
1332 isc_hmacsha384_invalidate(isc_hmacsha384_t *ctx) {
1333 isc_safe_memwipe(ctx, sizeof(*ctx));
1341 isc_hmacsha384_update(isc_hmacsha384_t *ctx, const unsigned char *buf,
1344 isc_sha384_update(&ctx->sha384ctx, buf, len);
1351 isc_hmacsha384_sign(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len) {
1357 isc_sha384_final(newdigest, &ctx->sha384ctx);
1361 opad[i] ^= ctx->key[i];
1363 isc_sha384_init(&ctx->sha384ctx);
1364 isc_sha384_update(&ctx->sha384ctx, opad, sizeof(opad));
1365 isc_sha384_update(&ctx->sha384ctx, newdigest, ISC_SHA384_DIGESTLENGTH);
1366 isc_sha384_final(newdigest, &ctx->sha384ctx);
1375 isc_hmacsha512_init(isc_hmacsha512_t *ctx, const unsigned char *key,
1381 memset(ctx->key, 0, sizeof(ctx->key));
1382 if (len > sizeof(ctx->key)) {
1386 isc_sha512_final(ctx->key, &sha512ctx);
1388 memmove(ctx->key, key, len);
1390 isc_sha512_init(&ctx->sha512ctx);
1393 ipad[i] ^= ctx->key[i];
1394 isc_sha512_update(&ctx->sha512ctx, ipad, sizeof(ipad));
1398 isc_hmacsha512_invalidate(isc_hmacsha512_t *ctx) {
1399 isc_safe_memwipe(ctx, sizeof(*ctx));
1407 isc_hmacsha512_update(isc_hmacsha512_t *ctx, const unsigned char *buf,
1410 isc_sha512_update(&ctx->sha512ctx, buf, len);
1417 isc_hmacsha512_sign(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len) {
1423 isc_sha512_final(newdigest, &ctx->sha512ctx);
1427 opad[i] ^= ctx->key[i];
1429 isc_sha512_init(&ctx->sha512ctx);
1430 isc_sha512_update(&ctx->sha512ctx, opad, sizeof(opad));
1431 isc_sha512_update(&ctx->sha512ctx, newdigest, ISC_SHA512_DIGESTLENGTH);
1432 isc_sha512_final(newdigest, &ctx->sha512ctx);
1443 isc_hmacsha1_verify(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len) {
1447 isc_hmacsha1_sign(ctx, newdigest, ISC_SHA1_DIGESTLENGTH);
1456 isc_hmacsha224_verify(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len) {
1460 isc_hmacsha224_sign(ctx, newdigest, ISC_SHA224_DIGESTLENGTH);
1469 isc_hmacsha256_verify(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len) {
1473 isc_hmacsha256_sign(ctx, newdigest, ISC_SHA256_DIGESTLENGTH);
1482 isc_hmacsha384_verify(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len) {
1486 isc_hmacsha384_sign(ctx, newdigest, ISC_SHA384_DIGESTLENGTH);
1495 isc_hmacsha512_verify(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len) {
1499 isc_hmacsha512_sign(ctx, newdigest, ISC_SHA512_DIGESTLENGTH);
1514 isc_hmacsha1_t ctx;
1559 isc_hmacsha1_init(&ctx, key, 20U);
1560 isc_hmacsha1_update(&ctx, input, 8U);
1561 result = isc_hmacsha1_verify(&ctx, expected, sizeof(expected));
1567 isc_hmacsha1_init(&ctx, key, 1U);
1568 isc_hmacsha1_update(&ctx, input, 8U);
1569 return (isc_hmacsha1_verify(&ctx, expected2, sizeof(expected2)));