| 1005 | } |
| 1006 | |
| 1007 | static int |
| 1008 | cryptodev_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 | } |
no test coverage detected