| 1084 | } |
| 1085 | |
| 1086 | static int |
| 1087 | swcr_setup_gcm(struct swcr_session *ses, |
| 1088 | const struct crypto_session_params *csp) |
| 1089 | { |
| 1090 | struct swcr_auth *swa; |
| 1091 | struct auth_hash *axf; |
| 1092 | |
| 1093 | if (csp->csp_ivlen != AES_GCM_IV_LEN) |
| 1094 | return (EINVAL); |
| 1095 | |
| 1096 | /* First, setup the auth side. */ |
| 1097 | swa = &ses->swcr_auth; |
| 1098 | switch (csp->csp_cipher_klen * 8) { |
| 1099 | case 128: |
| 1100 | axf = &auth_hash_nist_gmac_aes_128; |
| 1101 | break; |
| 1102 | case 192: |
| 1103 | axf = &auth_hash_nist_gmac_aes_192; |
| 1104 | break; |
| 1105 | case 256: |
| 1106 | axf = &auth_hash_nist_gmac_aes_256; |
| 1107 | break; |
| 1108 | default: |
| 1109 | return (EINVAL); |
| 1110 | } |
| 1111 | swa->sw_axf = axf; |
| 1112 | if (csp->csp_auth_mlen < 0 || csp->csp_auth_mlen > axf->hashsize) |
| 1113 | return (EINVAL); |
| 1114 | if (csp->csp_auth_mlen == 0) |
| 1115 | swa->sw_mlen = axf->hashsize; |
| 1116 | else |
| 1117 | swa->sw_mlen = csp->csp_auth_mlen; |
| 1118 | swa->sw_ictx = malloc(axf->ctxsize, M_CRYPTO_DATA, M_NOWAIT); |
| 1119 | if (swa->sw_ictx == NULL) |
| 1120 | return (ENOBUFS); |
| 1121 | axf->Init(swa->sw_ictx); |
| 1122 | if (csp->csp_cipher_key != NULL) |
| 1123 | axf->Setkey(swa->sw_ictx, csp->csp_cipher_key, |
| 1124 | csp->csp_cipher_klen); |
| 1125 | |
| 1126 | /* Second, setup the cipher side. */ |
| 1127 | return (swcr_setup_cipher(ses, csp)); |
| 1128 | } |
| 1129 | |
| 1130 | static int |
| 1131 | swcr_setup_ccm(struct swcr_session *ses, |
no test coverage detected