Changeset View
Changeset View
Standalone View
Standalone View
sys/crypto/aesni/aesni.c
Show First 20 Lines • Show All 694 Lines • ▼ Show 20 Lines | |||||
aesni_cipher_crypt(struct aesni_session *ses, struct cryptop *crp, | aesni_cipher_crypt(struct aesni_session *ses, struct cryptop *crp, | ||||
const struct crypto_session_params *csp) | const struct crypto_session_params *csp) | ||||
{ | { | ||||
uint8_t iv[AES_BLOCK_LEN], tag[GMAC_DIGEST_LEN]; | uint8_t iv[AES_BLOCK_LEN], tag[GMAC_DIGEST_LEN]; | ||||
uint8_t *authbuf, *buf, *outbuf; | uint8_t *authbuf, *buf, *outbuf; | ||||
int error; | int error; | ||||
bool encflag, allocated, authallocated, outallocated, outcopy; | bool encflag, allocated, authallocated, outallocated, outcopy; | ||||
if (crp->crp_payload_length == 0) { | |||||
buf = NULL; | |||||
allocated = false; | |||||
} else { | |||||
buf = aesni_cipher_alloc(crp, crp->crp_payload_start, | buf = aesni_cipher_alloc(crp, crp->crp_payload_start, | ||||
crp->crp_payload_length, &allocated); | crp->crp_payload_length, &allocated); | ||||
if (buf == NULL) | if (buf == NULL) | ||||
return (ENOMEM); | return (ENOMEM); | ||||
} | |||||
outallocated = false; | outallocated = false; | ||||
authallocated = false; | authallocated = false; | ||||
authbuf = NULL; | authbuf = NULL; | ||||
if (csp->csp_cipher_alg == CRYPTO_AES_NIST_GCM_16 || | if (csp->csp_cipher_alg == CRYPTO_AES_NIST_GCM_16 || | ||||
csp->csp_cipher_alg == CRYPTO_AES_CCM_16) { | csp->csp_cipher_alg == CRYPTO_AES_CCM_16) { | ||||
if (crp->crp_aad != NULL) | if (crp->crp_aad_length == 0) | ||||
authbuf = NULL; | |||||
else if (crp->crp_aad != NULL) | |||||
authbuf = crp->crp_aad; | authbuf = crp->crp_aad; | ||||
else | else { | ||||
emaste: this seems like it could be a reasonable place to apply `{}` on all branches if at least some… | |||||
authbuf = aesni_cipher_alloc(crp, crp->crp_aad_start, | authbuf = aesni_cipher_alloc(crp, crp->crp_aad_start, | ||||
crp->crp_aad_length, &authallocated); | crp->crp_aad_length, &authallocated); | ||||
if (authbuf == NULL) { | if (authbuf == NULL) { | ||||
error = ENOMEM; | error = ENOMEM; | ||||
goto out; | goto out; | ||||
} | } | ||||
} | } | ||||
} | |||||
if (CRYPTO_HAS_OUTPUT_BUFFER(crp)) { | if (CRYPTO_HAS_OUTPUT_BUFFER(crp) && crp->crp_payload_length > 0) { | ||||
outbuf = crypto_buffer_contiguous_subsegment(&crp->crp_obuf, | outbuf = crypto_buffer_contiguous_subsegment(&crp->crp_obuf, | ||||
crp->crp_payload_output_start, crp->crp_payload_length); | crp->crp_payload_output_start, crp->crp_payload_length); | ||||
if (outbuf == NULL) { | if (outbuf == NULL) { | ||||
outcopy = true; | outcopy = true; | ||||
if (allocated) | if (allocated) | ||||
outbuf = buf; | outbuf = buf; | ||||
else { | else { | ||||
outbuf = malloc(crp->crp_payload_length, | outbuf = malloc(crp->crp_payload_length, | ||||
▲ Show 20 Lines • Show All 196 Lines • Show Last 20 Lines |
this seems like it could be a reasonable place to apply {} on all branches if at least some have them