| 1 | /******************************************************************************* |
| 2 | Copyright (c) 2023-2024, Intel Corporation |
| 3 | |
| 4 | Redistribution and use in source and binary forms, with or without |
| 5 | modification, are permitted provided that the following conditions are met: |
| 6 | |
| 7 | * Redistributions of source code must retain the above copyright notice, |
| 8 | this list of conditions and the following disclaimer. |
| 9 | * Redistributions in binary form must reproduce the above copyright |
| 10 | notice, this list of conditions and the following disclaimer in the |
| 11 | documentation and/or other materials provided with the distribution. |
| 12 | * Neither the name of Intel Corporation nor the names of its contributors |
| 13 | may be used to endorse or promote products derived from this software |
| 14 | without specific prior written permission. |
| 15 | |
| 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | #include "intel-ipsec-mb.h"cxx . . $ `<file>/lib/intel-ipsec-mb.h`/ |
| 29 | #include "include/error.h"cxx . . $ `<file>/lib/include/error.h`/ |
| 30 | |
| 31 | IMB_DLL_EXPORTcxx . . $ `lib/intel-ipsec-mb.h:54:9`! void |
| 32 | imb_quic_aes_gcmcxx . . $ imb_quic_aes_gcm(6f75f0f96324c97e).(IMB_MGRcxx . . $ IMB_MGR# *state, const struct gcm_key_datacxx . . $ gcm_key_data# *key_data, |
| 33 | const IMB_KEY_SIZE_BYTEScxx . . $ IMB_KEY_SIZE_BYTES# key_size, const IMB_CIPHER_DIRECTIONcxx . . $ IMB_CIPHER_DIRECTION# cipher_dir, |
| 34 | void *dst_ptr_array[], const void *const src_ptr_array[], |
| 35 | const uint64_tcxx . . $ uint64_t# len_array[], const void *const iv_ptr_array[], |
| 36 | const void *const aad_ptr_array[], const uint64_tcxx . . $ uint64_t# aad_len, void *tag_ptr_array[], |
| 37 | const uint64_tcxx . . $ uint64_t# tag_len, const uint64_tcxx . . $ uint64_t# num_packets) |
| 38 | { |
| 39 | /** |
| 40 | * @note 12 byte IV is assumed |
| 41 | * @note it can be out of place operation |
| 42 | * but AAD needs to be copied by the caller |
| 43 | */ |
| 44 | struct gcm_context_datacxx . . $ gcm_context_data# ctx; |
| 45 | uint64_tcxx . . $ uint64_t# n; |
| 46 | |
| 47 | #ifdef SAFE_PARAMcxx . . $ `<built-in>:422:9`! |
| 48 | if (state == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 49 | imb_set_errnocxx . . $ imb_set_errno(beec41fcb78e7267).(NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!, IMB_ERR_NULL_MBMGRcxx . . $ IMB_ERR_NULL_MBMGR.); |
| 50 | return; |
| 51 | } |
| 52 | if (key_data == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 53 | imb_set_errnocxx . . $ imb_set_errno(beec41fcb78e7267).(state, IMB_ERR_NULL_EXP_KEYcxx . . $ IMB_ERR_NULL_EXP_KEY.); |
| 54 | return; |
| 55 | } |
| 56 | if (dst_ptr_array == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 57 | imb_set_errnocxx . . $ imb_set_errno(beec41fcb78e7267).(state, IMB_ERR_NULL_DSTcxx . . $ IMB_ERR_NULL_DST.); |
| 58 | return; |
| 59 | } |
| 60 | if (src_ptr_array == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 61 | imb_set_errnocxx . . $ imb_set_errno(beec41fcb78e7267).(state, IMB_ERR_NULL_SRCcxx . . $ IMB_ERR_NULL_SRC.); |
| 62 | return; |
| 63 | } |
| 64 | if (iv_ptr_array == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 65 | imb_set_errnocxx . . $ imb_set_errno(beec41fcb78e7267).(state, IMB_ERR_NULL_IVcxx . . $ IMB_ERR_NULL_IV.); |
| 66 | return; |
| 67 | } |
| 68 | if (aad_ptr_array == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 69 | imb_set_errnocxx . . $ imb_set_errno(beec41fcb78e7267).(state, IMB_ERR_NULL_AADcxx . . $ IMB_ERR_NULL_AAD.); |
| 70 | return; |
| 71 | } |
| 72 | if (tag_ptr_array == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 73 | imb_set_errnocxx . . $ imb_set_errno(beec41fcb78e7267).(state, IMB_ERR_NULL_AUTHcxx . . $ IMB_ERR_NULL_AUTH.); |
| 74 | return; |
| 75 | } |
| 76 | for (n = 0; n < num_packets; n++) { |
| 77 | if (dst_ptr_array[n] == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! && len_array[n] != 0) { |
| 78 | imb_set_errnocxx . . $ imb_set_errno(beec41fcb78e7267).(state, IMB_ERR_NULL_DSTcxx . . $ IMB_ERR_NULL_DST.); |
| 79 | return; |
| 80 | } |
| 81 | if (src_ptr_array[n] == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! && len_array[n] != 0) { |
| 82 | imb_set_errnocxx . . $ imb_set_errno(beec41fcb78e7267).(state, IMB_ERR_NULL_SRCcxx . . $ IMB_ERR_NULL_SRC.); |
| 83 | return; |
| 84 | } |
| 85 | if (iv_ptr_array[n] == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 86 | imb_set_errnocxx . . $ imb_set_errno(beec41fcb78e7267).(state, IMB_ERR_NULL_IVcxx . . $ IMB_ERR_NULL_IV.); |
| 87 | return; |
| 88 | } |
| 89 | if (aad_ptr_array[n] == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! && aad_len != 0) { |
| 90 | imb_set_errnocxx . . $ imb_set_errno(beec41fcb78e7267).(state, IMB_ERR_NULL_AADcxx . . $ IMB_ERR_NULL_AAD.); |
| 91 | return; |
| 92 | } |
| 93 | if (tag_ptr_array[n] == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 94 | imb_set_errnocxx . . $ imb_set_errno(beec41fcb78e7267).(state, IMB_ERR_NULL_AUTHcxx . . $ IMB_ERR_NULL_AUTH.); |
| 95 | return; |
| 96 | } |
| 97 | } |
| 98 | switch (key_size) { |
| 99 | case IMB_KEY_128_BYTEScxx . . $ IMB_KEY_128_BYTES.: |
| 100 | case IMB_KEY_256_BYTEScxx . . $ IMB_KEY_256_BYTES.: |
| 101 | break; |
| 102 | case IMB_KEY_192_BYTEScxx . . $ IMB_KEY_192_BYTES.: |
| 103 | /* AES-192 is not supported by QUIC */ |
| 104 | default: |
| 105 | imb_set_errnocxx . . $ imb_set_errno(beec41fcb78e7267).(state, IMB_ERR_KEY_LENcxx . . $ IMB_ERR_KEY_LEN.); |
| 106 | return; |
| 107 | } |
| 108 | switch (cipher_dir) { |
| 109 | case IMB_DIR_ENCRYPTcxx . . $ IMB_DIR_ENCRYPT.: |
| 110 | case IMB_DIR_DECRYPTcxx . . $ IMB_DIR_DECRYPT.: |
| 111 | break; |
| 112 | default: |
| 113 | imb_set_errnocxx . . $ imb_set_errno(beec41fcb78e7267).(state, IMB_ERR_JOB_CIPH_DIRcxx . . $ IMB_ERR_JOB_CIPH_DIR.); |
| 114 | return; |
| 115 | } |
| 116 | #endif /* SAFE_PARAM */ |
| 117 | |
| 118 | if (cipher_dir == IMB_DIR_ENCRYPTcxx . . $ IMB_DIR_ENCRYPT.) { |
| 119 | if (key_size == IMB_KEY_128_BYTEScxx . . $ IMB_KEY_128_BYTES.) { |
| 120 | for (n = 0; n < num_packets; n++) { |
| 121 | IMB_AES128_GCM_ENCcxx . . $ `lib/intel-ipsec-mb.h:1914:9`!(state, key_data, &ctx, dst_ptr_array[n], |
| 122 | src_ptr_array[n], len_array[n], iv_ptr_array[n], |
| 123 | aad_ptr_array[n], aad_len, tag_ptr_array[n], |
| 124 | tag_len); |
| 125 | } |
| 126 | } else /* assume 256-bits key */ { |
| 127 | for (n = 0; n < num_packets; n++) { |
| 128 | IMB_AES256_GCM_ENCcxx . . $ `lib/intel-ipsec-mb.h:1920:9`!(state, key_data, &ctx, dst_ptr_array[n], |
| 129 | src_ptr_array[n], len_array[n], iv_ptr_array[n], |
| 130 | aad_ptr_array[n], aad_len, tag_ptr_array[n], |
| 131 | tag_len); |
| 132 | } |
| 133 | } |
| 134 | } else /* decrypt direction */ { |
| 135 | if (key_size == IMB_KEY_128_BYTEScxx . . $ IMB_KEY_128_BYTES.) { |
| 136 | for (n = 0; n < num_packets; n++) { |
| 137 | IMB_AES128_GCM_DECcxx . . $ `lib/intel-ipsec-mb.h:1924:9`!(state, key_data, &ctx, dst_ptr_array[n], |
| 138 | src_ptr_array[n], len_array[n], iv_ptr_array[n], |
| 139 | aad_ptr_array[n], aad_len, tag_ptr_array[n], |
| 140 | tag_len); |
| 141 | } |
| 142 | } else /* assume 256-bits key */ { |
| 143 | for (n = 0; n < num_packets; n++) { |
| 144 | IMB_AES256_GCM_DECcxx . . $ `lib/intel-ipsec-mb.h:1930:9`!(state, key_data, &ctx, dst_ptr_array[n], |
| 145 | src_ptr_array[n], len_array[n], iv_ptr_array[n], |
| 146 | aad_ptr_array[n], aad_len, tag_ptr_array[n], |
| 147 | tag_len); |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | } |