* NB: public for use by esp_init. */
| 172 | * NB: public for use by esp_init. |
| 173 | */ |
| 174 | int |
| 175 | ah_init0(struct secasvar *sav, struct xformsw *xsp, |
| 176 | struct crypto_session_params *csp) |
| 177 | { |
| 178 | const struct auth_hash *thash; |
| 179 | int keylen; |
| 180 | |
| 181 | thash = auth_algorithm_lookup(sav->alg_auth); |
| 182 | if (thash == NULL) { |
| 183 | DPRINTF(("%s: unsupported authentication algorithm %u\n", |
| 184 | __func__, sav->alg_auth)); |
| 185 | return EINVAL; |
| 186 | } |
| 187 | |
| 188 | /* |
| 189 | * Verify the replay state block allocation is consistent with |
| 190 | * the protocol type. We check here so we can make assumptions |
| 191 | * later during protocol processing. |
| 192 | */ |
| 193 | /* NB: replay state is setup elsewhere (sigh) */ |
| 194 | if (((sav->flags&SADB_X_EXT_OLD) == 0) ^ (sav->replay != NULL)) { |
| 195 | DPRINTF(("%s: replay state block inconsistency, " |
| 196 | "%s algorithm %s replay state\n", __func__, |
| 197 | (sav->flags & SADB_X_EXT_OLD) ? "old" : "new", |
| 198 | sav->replay == NULL ? "without" : "with")); |
| 199 | return EINVAL; |
| 200 | } |
| 201 | if (sav->key_auth == NULL) { |
| 202 | DPRINTF(("%s: no authentication key for %s algorithm\n", |
| 203 | __func__, thash->name)); |
| 204 | return EINVAL; |
| 205 | } |
| 206 | keylen = _KEYLEN(sav->key_auth); |
| 207 | if (keylen > thash->keysize && thash->keysize != 0) { |
| 208 | DPRINTF(("%s: invalid keylength %d, algorithm %s requires " |
| 209 | "keysize less than %d\n", __func__, |
| 210 | keylen, thash->name, thash->keysize)); |
| 211 | return EINVAL; |
| 212 | } |
| 213 | |
| 214 | sav->tdb_xform = xsp; |
| 215 | sav->tdb_authalgxform = thash; |
| 216 | |
| 217 | /* Initialize crypto session. */ |
| 218 | csp->csp_auth_alg = sav->tdb_authalgxform->type; |
| 219 | if (csp->csp_auth_alg != CRYPTO_NULL_HMAC) { |
| 220 | csp->csp_auth_klen = _KEYBITS(sav->key_auth) / 8; |
| 221 | csp->csp_auth_key = sav->key_auth->key_data; |
| 222 | }; |
| 223 | csp->csp_auth_mlen = AUTHSIZE(sav); |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | /* |
| 229 | * ah_init() is called when an SPI is being set up. |
no test coverage detected