MCPcopy Create free account
hub / github.com/F-Stack/f-stack / cryptodev_aead

Function cryptodev_aead

freebsd/opencrypto/cryptodev.c:1007–1198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1005}
1006
1007static int
1008cryptodev_aead(struct csession *cse, struct crypt_aead *caead)
1009{
1010 struct cryptop_data *cod = NULL;
1011 struct cryptop *crp = NULL;
1012 char *dst;
1013 int error;
1014
1015 if (caead->len > 256*1024-4 || caead->aadlen > 256*1024-4) {
1016 SDT_PROBE1(opencrypto, dev, ioctl, error, __LINE__);
1017 return (E2BIG);
1018 }
1019
1020 if (cse->txform == NULL || cse->hashsize == 0 || caead->tag == NULL ||
1021 (caead->len % cse->txform->blocksize) != 0) {
1022 SDT_PROBE1(opencrypto, dev, ioctl, error, __LINE__);
1023 return (EINVAL);
1024 }
1025
1026 /*
1027 * The COP_F_CIPHER_FIRST flag predates explicit session
1028 * modes, but the only way it was used was for EtA so allow it
1029 * as long as it is consistent with EtA.
1030 */
1031 if (caead->flags & COP_F_CIPHER_FIRST) {
1032 if (caead->op != COP_ENCRYPT) {
1033 SDT_PROBE1(opencrypto, dev, ioctl, error, __LINE__);
1034 return (EINVAL);
1035 }
1036 }
1037
1038 cod = cod_alloc(cse, caead->aadlen, caead->len + cse->hashsize);
1039 dst = caead->dst;
1040
1041 crp = crypto_getreq(cse->cses, M_WAITOK);
1042
1043 if (cod->aad != NULL)
1044 error = copyin(caead->aad, cod->aad, caead->aadlen);
1045 else
1046 error = copyin(caead->aad, cod->buf, caead->aadlen);
1047 if (error) {
1048 SDT_PROBE1(opencrypto, dev, ioctl, error, __LINE__);
1049 goto bail;
1050 }
1051 crp->crp_aad = cod->aad;
1052 crp->crp_aad_start = 0;
1053 crp->crp_aad_length = caead->aadlen;
1054
1055 if (cod->aad != NULL)
1056 crp->crp_payload_start = 0;
1057 else
1058 crp->crp_payload_start = caead->aadlen;
1059 error = copyin(caead->src, cod->buf + crp->crp_payload_start,
1060 caead->len);
1061 if (error) {
1062 SDT_PROBE1(opencrypto, dev, ioctl, error, __LINE__);
1063 goto bail;
1064 }

Callers 1

crypto_ioctlFunction · 0.85

Calls 11

cod_allocFunction · 0.85
crypto_getreqFunction · 0.85
crypto_use_bufFunction · 0.85
crypto_use_output_bufFunction · 0.85
crypto_dispatchFunction · 0.85
crypto_freereqFunction · 0.85
cod_freeFunction · 0.85
copyinFunction · 0.50
mtx_lockFunction · 0.50
mtx_unlockFunction · 0.50
copyoutFunction · 0.50

Tested by

no test coverage detected