* computes the requested HMAC using a key struct (which may be modified if * the keylen exceeds the HMAC block len). */
| 1054 | * the keylen exceeds the HMAC block len). |
| 1055 | */ |
| 1056 | uint32_t |
| 1057 | sctp_compute_hmac(uint16_t hmac_algo, sctp_key_t *key, uint8_t *text, |
| 1058 | uint32_t textlen, uint8_t *digest) |
| 1059 | { |
| 1060 | uint32_t digestlen; |
| 1061 | uint32_t blocklen; |
| 1062 | sctp_hash_context_t ctx; |
| 1063 | uint8_t temp[SCTP_AUTH_DIGEST_LEN_MAX]; |
| 1064 | |
| 1065 | /* sanity check */ |
| 1066 | if ((key == NULL) || (text == NULL) || (textlen == 0) || |
| 1067 | (digest == NULL)) { |
| 1068 | /* can't do HMAC with empty key or text or digest store */ |
| 1069 | return (0); |
| 1070 | } |
| 1071 | /* validate the hmac algo and get the digest length */ |
| 1072 | digestlen = sctp_get_hmac_digest_len(hmac_algo); |
| 1073 | if (digestlen == 0) |
| 1074 | return (0); |
| 1075 | |
| 1076 | /* hash the key if it is longer than the hash block size */ |
| 1077 | blocklen = sctp_get_hmac_block_len(hmac_algo); |
| 1078 | if (key->keylen > blocklen) { |
| 1079 | sctp_hmac_init(hmac_algo, &ctx); |
| 1080 | sctp_hmac_update(hmac_algo, &ctx, key->key, key->keylen); |
| 1081 | sctp_hmac_final(hmac_algo, &ctx, temp); |
| 1082 | /* save the hashed key as the new key */ |
| 1083 | key->keylen = digestlen; |
| 1084 | memcpy(key->key, temp, key->keylen); |
| 1085 | } |
| 1086 | return (sctp_hmac(hmac_algo, key->key, key->keylen, text, textlen, |
| 1087 | digest)); |
| 1088 | } |
| 1089 | |
| 1090 | /* mbuf version */ |
| 1091 | uint32_t |
nothing calls this directly
no test coverage detected