Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/cxgbe/crypto/t4_crypto.c
/*- | /*- | ||||
* Copyright (c) 2017 Chelsio Communications, Inc. | * Copyright (c) 2017 Chelsio Communications, Inc. | ||||
* Copyright (c) 2021 The FreeBSD Foundation | |||||
* All rights reserved. | * All rights reserved. | ||||
* Written by: John Baldwin <jhb@FreeBSD.org> | * Written by: John Baldwin <jhb@FreeBSD.org> | ||||
* | * | ||||
* Portions of this software were developed by Ararat River | |||||
* Consulting, LLC under sponsorship of the FreeBSD Foundation. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
* notice, this list of conditions and the following disclaimer in the | * notice, this list of conditions and the following disclaimer in the | ||||
* documentation and/or other materials provided with the distribution. | * documentation and/or other materials provided with the distribution. | ||||
▲ Show 20 Lines • Show All 1,439 Lines • ▼ Show 20 Lines | for (i = 0; i < crp->crp_aad_length; i += sizeof(block)) { | ||||
len = imin(crp->crp_aad_length - i, sizeof(block)); | len = imin(crp->crp_aad_length - i, sizeof(block)); | ||||
crypto_copydata(crp, crp->crp_aad_start + i, len, | crypto_copydata(crp, crp->crp_aad_start + i, len, | ||||
block); | block); | ||||
bzero(block + len, sizeof(block) - len); | bzero(block + len, sizeof(block) - len); | ||||
axf->Update(auth_ctx, block, sizeof(block)); | axf->Update(auth_ctx, block, sizeof(block)); | ||||
} | } | ||||
} | } | ||||
exf->reinit(kschedule, iv); | exf->reinit(kschedule, iv, sizeof(iv)); | ||||
/* Do encryption with MAC */ | /* Do encryption with MAC */ | ||||
for (i = 0; i < crp->crp_payload_length; i += sizeof(block)) { | for (i = 0; i < crp->crp_payload_length; i += sizeof(block)) { | ||||
len = imin(crp->crp_payload_length - i, sizeof(block)); | len = imin(crp->crp_payload_length - i, sizeof(block)); | ||||
crypto_copydata(crp, crp->crp_payload_start + i, len, block); | crypto_copydata(crp, crp->crp_payload_start + i, len, block); | ||||
bzero(block + len, sizeof(block) - len); | bzero(block + len, sizeof(block) - len); | ||||
if (CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) { | if (CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) { | ||||
exf->encrypt(kschedule, block, block); | exf->encrypt(kschedule, block, block); | ||||
▲ Show 20 Lines • Show All 460 Lines • ▼ Show 20 Lines | if (crp->crp_aad != NULL) | ||||
error = axf->Update(auth_ctx, crp->crp_aad, | error = axf->Update(auth_ctx, crp->crp_aad, | ||||
crp->crp_aad_length); | crp->crp_aad_length); | ||||
else | else | ||||
error = crypto_apply(crp, crp->crp_aad_start, | error = crypto_apply(crp, crp->crp_aad_start, | ||||
crp->crp_aad_length, axf->Update, auth_ctx); | crp->crp_aad_length, axf->Update, auth_ctx); | ||||
if (error) | if (error) | ||||
goto out; | goto out; | ||||
exf->reinit(kschedule, iv); | exf->reinit(kschedule, iv, sizeof(iv)); | ||||
/* Do encryption/decryption with MAC */ | /* Do encryption/decryption with MAC */ | ||||
for (i = 0; i < crp->crp_payload_length; i += sizeof(block)) { | for (i = 0; i < crp->crp_payload_length; i += sizeof(block)) { | ||||
len = imin(crp->crp_payload_length - i, sizeof(block)); | len = imin(crp->crp_payload_length - i, sizeof(block)); | ||||
crypto_copydata(crp, crp->crp_payload_start + i, len, block); | crypto_copydata(crp, crp->crp_payload_start + i, len, block); | ||||
bzero(block + len, sizeof(block) - len); | bzero(block + len, sizeof(block) - len); | ||||
if (CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) { | if (CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) { | ||||
axf->Update(auth_ctx, block, len); | axf->Update(auth_ctx, block, len); | ||||
Show All 18 Lines | if (CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) { | ||||
char digest2[AES_CBC_MAC_HASH_LEN]; | char digest2[AES_CBC_MAC_HASH_LEN]; | ||||
crypto_copydata(crp, crp->crp_digest_start, sizeof(digest2), | crypto_copydata(crp, crp->crp_digest_start, sizeof(digest2), | ||||
digest2); | digest2); | ||||
if (timingsafe_bcmp(digest, digest2, sizeof(digest)) == 0) { | if (timingsafe_bcmp(digest, digest2, sizeof(digest)) == 0) { | ||||
error = 0; | error = 0; | ||||
/* Tag matches, decrypt data. */ | /* Tag matches, decrypt data. */ | ||||
exf->reinit(kschedule, iv); | exf->reinit(kschedule, iv, sizeof(iv)); | ||||
for (i = 0; i < crp->crp_payload_length; | for (i = 0; i < crp->crp_payload_length; | ||||
i += sizeof(block)) { | i += sizeof(block)) { | ||||
len = imin(crp->crp_payload_length - i, | len = imin(crp->crp_payload_length - i, | ||||
sizeof(block)); | sizeof(block)); | ||||
crypto_copydata(crp, crp->crp_payload_start + i, | crypto_copydata(crp, crp->crp_payload_start + i, | ||||
len, block); | len, block); | ||||
bzero(block + len, sizeof(block) - len); | bzero(block + len, sizeof(block) - len); | ||||
exf->decrypt(kschedule, block, block); | exf->decrypt(kschedule, block, block); | ||||
▲ Show 20 Lines • Show All 977 Lines • Show Last 20 Lines |