| 1 | /************************************************************************* |
| 2 | * Copyright (C) 2010 Intel Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | *************************************************************************/ |
| 16 | |
| 17 | /* |
| 18 | // |
| 19 | // Purpose: |
| 20 | // Cryptography Primitive. |
| 21 | // Encrypt/Decrypt byte data stream according to Rijndael128 (GCM mode) |
| 22 | // |
| 23 | // "fast" stuff |
| 24 | // |
| 25 | // Contents: |
| 26 | // wrpAesGcmEnc_table2K() |
| 27 | // |
| 28 | */ |
| 29 | |
| 30 | |
| 31 | #include "owndefs.h" |
| 32 | #include "owncp.h" |
| 33 | |
| 34 | #include "pcpaesauthgcm.h" |
| 35 | #include "pcptool.h" |
| 36 | |
| 37 | #if (_ALG_AES_SAFE_ == _ALG_AES_SAFE_COMPACT_SBOX_) |
| 38 | #include "pcprijtables.h" |
| 39 | #endif |
| 40 | |
| 41 | #if (_IPP32E < _IPP32E_K0) |
| 42 | |
| 43 | /* |
| 44 | // encrypts and authenticates n*BLOCK_SIZE bytes |
| 45 | */ |
| 46 | /* clang-format off */ |
| 47 | IPP_OWN_DEFN(void, wrpAesGcmEnc_table2K, (Ipp8u* pDst, |
| 48 | const Ipp8u* pSrc, |
| 49 | int len, |
| 50 | IppsAES_GCMState* pState)) |
| 51 | /* clang-format on */ |
| 52 | { |
| 53 | Ipp8u* pHashedData = pDst; |
| 54 | int hashedDataLen = len; |
| 55 | |
| 56 | Ipp8u* pCounter = AESGCM_COUNTER(pState); |
| 57 | Ipp8u* pECounter = AESGCM_ECOUNTER(pState); |
| 58 | |
| 59 | IppsRijndael128Spec* pAES = AESGCM_CIPHER(pState); |
| 60 | RijnCipher encoder = RIJ_ENCODER(pAES); |
| 61 | |
| 62 | while (len >= BLOCK_SIZE) { |
| 63 | /* encrypt whole AES block */ |
| 64 | XorBlock16(pSrc, pECounter, pDst); |
| 65 | |
| 66 | pSrc += BLOCK_SIZE; |
| 67 | pDst += BLOCK_SIZE; |
| 68 | len -= BLOCK_SIZE; |
| 69 | |
| 70 | /* increment counter block */ |
| 71 | IncrementCounter32(pCounter); |
| 72 | /* and encrypt counter */ |
| 73 | //encoder((Ipp32u*)pCounter, (Ipp32u*)pECounter, RIJ_NR(pAES), RIJ_EKEYS(pAES), (const Ipp32u (*)[256])RIJ_ENC_SBOX(pAES)); |
| 74 | #if (_ALG_AES_SAFE_ == _ALG_AES_SAFE_COMPACT_SBOX_) |
| 75 | encoder(pCounter, pECounter, RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox /*NULL*/); |
| 76 | #else |
| 77 | encoder(pCounter, pECounter, RIJ_NR(pAES), RIJ_EKEYS(pAES), NULL); |
| 78 | #endif |
| 79 | } |
| 80 | |
| 81 | //AesGcmAuth_table2K(AESGCM_GHASH(pState), pHashedData, hashedDataLen, AESGCM_HKEY(pState), AesGcmConst_table); |
| 82 | AesGcmAuth_table2K_ct(AESGCM_GHASH(pState), |
| 83 | pHashedData, |
| 84 | hashedDataLen, |
| 85 | AESGCM_HKEY(pState), |
| 86 | AesGcmConst_table); |
| 87 | } |
| 88 | |
| 89 | #endif |