crypto.c (54ae1f3308ca043d20f1757f3c5a99cba7feb3b8) crypto.c (29fe41ddd714bae92a09fd4098fad614945bedf5)
1/*-
2 * Copyright (c) 2002-2006 Sam Leffler. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 1266 unchanged lines hidden (view full) ---

1275 case CSP_MODE_ETA:
1276 KASSERT(crp->crp_op ==
1277 (CRYPTO_OP_ENCRYPT | CRYPTO_OP_COMPUTE_DIGEST) ||
1278 crp->crp_op ==
1279 (CRYPTO_OP_DECRYPT | CRYPTO_OP_VERIFY_DIGEST),
1280 ("invalid ETA op %x", crp->crp_op));
1281 break;
1282 }
1/*-
2 * Copyright (c) 2002-2006 Sam Leffler. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 1266 unchanged lines hidden (view full) ---

1275 case CSP_MODE_ETA:
1276 KASSERT(crp->crp_op ==
1277 (CRYPTO_OP_ENCRYPT | CRYPTO_OP_COMPUTE_DIGEST) ||
1278 crp->crp_op ==
1279 (CRYPTO_OP_DECRYPT | CRYPTO_OP_VERIFY_DIGEST),
1280 ("invalid ETA op %x", crp->crp_op));
1281 break;
1282 }
1283 KASSERT((crp->crp_flags & CRYPTO_F_IV_GENERATE) == 0 ||
1284 crp->crp_op == CRYPTO_OP_ENCRYPT ||
1285 crp->crp_op == (CRYPTO_OP_ENCRYPT | CRYPTO_OP_COMPUTE_DIGEST),
1286 ("IV_GENERATE set for non-encryption operation %x", crp->crp_op));
1287 KASSERT((crp->crp_flags &
1288 (CRYPTO_F_IV_SEPARATE | CRYPTO_F_IV_GENERATE)) !=
1289 (CRYPTO_F_IV_SEPARATE | CRYPTO_F_IV_GENERATE),
1290 ("crp with both IV_SEPARATE and IV_GENERATE set"));
1291 KASSERT(crp->crp_buf_type >= CRYPTO_BUF_CONTIG &&
1292 crp->crp_buf_type <= CRYPTO_BUF_MBUF,
1293 ("invalid crp buffer type %d", crp->crp_buf_type));
1294 if (csp->csp_mode == CSP_MODE_AEAD || csp->csp_mode == CSP_MODE_ETA) {
1295 KASSERT(crp->crp_aad_start == 0 ||
1296 crp->crp_aad_start < crp->crp_ilen,
1297 ("invalid AAD start"));
1298 KASSERT(crp->crp_aad_length != 0 || crp->crp_aad_start == 0,
1299 ("AAD with zero length and non-zero start"));
1300 KASSERT(crp->crp_aad_length == 0 ||
1301 crp->crp_aad_start + crp->crp_aad_length <= crp->crp_ilen,
1302 ("AAD outside input length"));
1303 } else {
1304 KASSERT(crp->crp_aad_start == 0 && crp->crp_aad_length == 0,
1305 ("AAD region in request not supporting AAD"));
1306 }
1307 if (csp->csp_ivlen == 0) {
1283 KASSERT(crp->crp_buf_type >= CRYPTO_BUF_CONTIG &&
1284 crp->crp_buf_type <= CRYPTO_BUF_MBUF,
1285 ("invalid crp buffer type %d", crp->crp_buf_type));
1286 if (csp->csp_mode == CSP_MODE_AEAD || csp->csp_mode == CSP_MODE_ETA) {
1287 KASSERT(crp->crp_aad_start == 0 ||
1288 crp->crp_aad_start < crp->crp_ilen,
1289 ("invalid AAD start"));
1290 KASSERT(crp->crp_aad_length != 0 || crp->crp_aad_start == 0,
1291 ("AAD with zero length and non-zero start"));
1292 KASSERT(crp->crp_aad_length == 0 ||
1293 crp->crp_aad_start + crp->crp_aad_length <= crp->crp_ilen,
1294 ("AAD outside input length"));
1295 } else {
1296 KASSERT(crp->crp_aad_start == 0 && crp->crp_aad_length == 0,
1297 ("AAD region in request not supporting AAD"));
1298 }
1299 if (csp->csp_ivlen == 0) {
1308 KASSERT((crp->crp_flags &
1309 (CRYPTO_F_IV_SEPARATE | CRYPTO_F_IV_GENERATE)) == 0,
1310 ("IV_GENERATE or IV_SEPARATE set when IV isn't used"));
1300 KASSERT((crp->crp_flags & CRYPTO_F_IV_SEPARATE) == 0,
1301 ("IV_SEPARATE set when IV isn't used"));
1311 KASSERT(crp->crp_iv_start == 0,
1312 ("crp_iv_start set when IV isn't used"));
1313 } else if (crp->crp_flags & CRYPTO_F_IV_SEPARATE) {
1314 KASSERT(crp->crp_iv_start == 0,
1315 ("IV_SEPARATE used with non-zero IV start"));
1316 } else {
1317 KASSERT(crp->crp_iv_start < crp->crp_ilen,
1318 ("invalid IV start"));

--- 37 unchanged lines hidden (view full) ---

1356{
1357 struct cryptocap *cap;
1358 int result;
1359
1360#ifdef INVARIANTS
1361 crp_sanity(crp);
1362#endif
1363
1302 KASSERT(crp->crp_iv_start == 0,
1303 ("crp_iv_start set when IV isn't used"));
1304 } else if (crp->crp_flags & CRYPTO_F_IV_SEPARATE) {
1305 KASSERT(crp->crp_iv_start == 0,
1306 ("IV_SEPARATE used with non-zero IV start"));
1307 } else {
1308 KASSERT(crp->crp_iv_start < crp->crp_ilen,
1309 ("invalid IV start"));

--- 37 unchanged lines hidden (view full) ---

1347{
1348 struct cryptocap *cap;
1349 int result;
1350
1351#ifdef INVARIANTS
1352 crp_sanity(crp);
1353#endif
1354
1364 /* TODO: Handle CRYPTO_F_IV_GENERATE so drivers don't have to. */
1365
1366 cryptostats.cs_ops++;
1367
1368#ifdef CRYPTO_TIMING
1369 if (crypto_timing)
1370 binuptime(&crp->crp_tstamp);
1371#endif
1372
1373 crp->crp_retw_id = ((uintptr_t)crp->crp_session) % crypto_workers_num;

--- 899 unchanged lines hidden ---
1355 cryptostats.cs_ops++;
1356
1357#ifdef CRYPTO_TIMING
1358 if (crypto_timing)
1359 binuptime(&crp->crp_tstamp);
1360#endif
1361
1362 crp->crp_retw_id = ((uintptr_t)crp->crp_session) % crypto_workers_num;

--- 899 unchanged lines hidden ---