Home | History | Annotate | Download | only in ippcp
      1 /*******************************************************************************
      2 * Copyright 2005-2018 Intel Corporation
      3 * All Rights Reserved.
      4 *
      5 * If this  software was obtained  under the  Intel Simplified  Software License,
      6 * the following terms apply:
      7 *
      8 * The source code,  information  and material  ("Material") contained  herein is
      9 * owned by Intel Corporation or its  suppliers or licensors,  and  title to such
     10 * Material remains with Intel  Corporation or its  suppliers or  licensors.  The
     11 * Material  contains  proprietary  information  of  Intel or  its suppliers  and
     12 * licensors.  The Material is protected by  worldwide copyright  laws and treaty
     13 * provisions.  No part  of  the  Material   may  be  used,  copied,  reproduced,
     14 * modified, published,  uploaded, posted, transmitted,  distributed or disclosed
     15 * in any way without Intel's prior express written permission.  No license under
     16 * any patent,  copyright or other  intellectual property rights  in the Material
     17 * is granted to  or  conferred  upon  you,  either   expressly,  by implication,
     18 * inducement,  estoppel  or  otherwise.  Any  license   under such  intellectual
     19 * property rights must be express and approved by Intel in writing.
     20 *
     21 * Unless otherwise agreed by Intel in writing,  you may not remove or alter this
     22 * notice or  any  other  notice   embedded  in  Materials  by  Intel  or Intel's
     23 * suppliers or licensors in any way.
     24 *
     25 *
     26 * If this  software  was obtained  under the  Apache License,  Version  2.0 (the
     27 * "License"), the following terms apply:
     28 *
     29 * You may  not use this  file except  in compliance  with  the License.  You may
     30 * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
     31 *
     32 *
     33 * Unless  required  by   applicable  law  or  agreed  to  in  writing,  software
     34 * distributed under the License  is distributed  on an  "AS IS"  BASIS,  WITHOUT
     35 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     36 *
     37 * See the   License  for the   specific  language   governing   permissions  and
     38 * limitations under the License.
     39 *******************************************************************************/
     40 
     41 /*
     42 //               Intel(R) Integrated Performance Primitives
     43 //                   Cryptographic Primitives (ippcp)
     44 //
     45 //   Purpose:
     46 //     Define ippCP variant
     47 //
     48 //
     49 */
     50 
     51 #if !defined(_CP_VARIANT_H)
     52 #define _CP_VARIANT_H
     53 
     54 /*
     55 // set _AES_NI_ENABLING_
     56 */
     57 #if defined _IPP_AES_NI_
     58    #if (_IPP_AES_NI_ == 0)
     59       #define _AES_NI_ENABLING_  _FEATURE_OFF_
     60    #elif  (_IPP_AES_NI_ == 1)
     61       #define _AES_NI_ENABLING_  _FEATURE_ON_
     62    #else
     63       #error Define _IPP_AES_NI_=0 or 1 or omit _IPP_AES_NI_ at all
     64    #endif
     65 #else
     66    #if (_IPP>=_IPP_P8) || (_IPP32E>=_IPP32E_Y8)
     67       #define _AES_NI_ENABLING_  _FEATURE_TICKTOCK_
     68    #else
     69       #define _AES_NI_ENABLING_  _FEATURE_OFF_
     70    #endif
     71 #endif
     72 
     73 /*
     74 // select AES safe implementation
     75 */
     76 #define _ALG_AES_SAFE_COMPACT_SBOX_ (1)
     77 #define _ALG_AES_SAFE_COMPOSITE_GF_ (2)
     78 
     79 #if (_AES_NI_ENABLING_==_FEATURE_ON_)
     80    #define _ALG_AES_SAFE_   _FEATURE_OFF_
     81 #else
     82    #if (_IPP>=_IPP_V8) || (_IPP32E>=_IPP32E_U8)
     83       #define _ALG_AES_SAFE_   _ALG_AES_SAFE_COMPOSITE_GF_
     84    #else
     85       #define _ALG_AES_SAFE_   _ALG_AES_SAFE_COMPACT_SBOX_
     86       //#define _ALG_AES_SAFE_   _ALG_AES_SAFE_COMPOSITE_GF_
     87    #endif
     88 #endif
     89 
     90 
     91 /*
     92 // if there is no outside assignment
     93 // set _SHA_NI_ENABLING_ based on CPU specification
     94 */
     95 #if !defined(_SHA_NI_ENABLING_)
     96 #if (_IPP>=_IPP_P8) || (_IPP32E>=_IPP32E_Y8)
     97    #define _SHA_NI_ENABLING_  _FEATURE_TICKTOCK_
     98 #else
     99    #define _SHA_NI_ENABLING_  _FEATURE_OFF_
    100 #endif
    101 #endif
    102 
    103 /*
    104 // set/reset _ADCOX_NI_ENABLING_
    105 */
    106 #if (_IPP32E>=_IPP32E_L9)
    107    #if !defined(_ADCOX_NI_ENABLING_)
    108       #define _ADCOX_NI_ENABLING_  _FEATURE_TICKTOCK_
    109    #endif
    110 #else
    111    #undef  _ADCOX_NI_ENABLING_
    112    #define _ADCOX_NI_ENABLING_  _FEATURE_OFF_
    113 #endif
    114 
    115 /*
    116 // Intel(R) Integrated Performance Primitives (Intel(R) IPP) supports several hash algorithms by default:
    117 //    SHA-1
    118 //    SHA-256
    119 //    SHA-224  (or SHA256/224 by the FIPS180-4 classification)
    120 //    SHA-512
    121 //    SHA-384  (or SHA512/384 by the FIPS180-4 classification)
    122 //    MD5
    123 //    SM3
    124 //
    125 // By default all hash algorithms are included in Intel(R) IPP Crypto.
    126 //
    127 // If one need excludes code of particular hash, just define
    128 // suitable _DISABLE_ALG_XXX, where XXX name of the hash algorithm
    129 //
    130 */
    131 #if !defined(_DISABLE_ALG_SHA1_)
    132 #define _ENABLE_ALG_SHA1_          /* SHA1        on  */
    133 #else
    134 #  undef  _ENABLE_ALG_SHA1_        /* SHA1        off */
    135 #endif
    136 
    137 #if !defined(_DISABLE_ALG_SHA256_)
    138 #  define _ENABLE_ALG_SHA256_      /* SHA256      on  */
    139 #else
    140 #  undef  _ENABLE_ALG_SHA256_      /* SHA256      off */
    141 #endif
    142 
    143 #if !defined(_DISABLE_ALG_SHA224_)
    144 #  define _ENABLE_ALG_SHA224_      /* SHA224      on  */
    145 #else
    146 #  undef  _ENABLE_ALG_SHA224_      /* SHA224      off */
    147 #endif
    148 
    149 #if !defined(_DISABLE_ALG_SHA512_)
    150 #  define _ENABLE_ALG_SHA512_      /* SHA512      on  */
    151 #else
    152 #  undef  _ENABLE_ALG_SHA512_      /* SHA512      off */
    153 #endif
    154 
    155 #if !defined(_DISABLE_ALG_SHA384_)
    156 #  define _ENABLE_ALG_SHA384_      /* SHA384      on  */
    157 #else
    158 #  undef  _ENABLE_ALG_SHA384_      /* SHA384      off */
    159 #endif
    160 
    161 #if !defined(_DISABLE_ALG_SHA512_224_)
    162 #  define _ENABLE_ALG_SHA512_224_  /* SHA512/224  on  */
    163 #else
    164 #  undef  _ENABLE_ALG_SHA512_224_  /* SHA512/224  off */
    165 #endif
    166 
    167 #if !defined(_DISABLE_ALG_SHA512_256_)
    168 #  define _ENABLE_ALG_SHA512_256_  /* SHA512/256  on  */
    169 #else
    170 #  undef  _ENABLE_ALG_SHA512_256_  /* SHA512/256  off */
    171 #endif
    172 
    173 #if !defined(_DISABLE_ALG_MD5_)
    174 #  define _ENABLE_ALG_MD5_         /* MD5         on  */
    175 #else
    176 #  undef  _ENABLE_ALG_MD5_         /* MD5         off */
    177 #endif
    178 
    179 #if !defined(_DISABLE_ALG_SM3_)
    180 #  define _ENABLE_ALG_SM3_         /* SM3         on  */
    181 #else
    182 #  undef  _ENABLE_ALG_SM3_         /* SM3         off */
    183 #endif
    184 
    185 /*
    186 // SHA1 plays especial role in Intel(R) IPP. Thus Intel(R) IPP random generator
    187 // and therefore prime number generator are based on SHA1.
    188 // So, do no exclude SHA1 from the active list of hash algorithms
    189 */
    190 #if defined(_DISABLE_ALG_SHA1_)
    191 #undef _DISABLE_ALG_SHA1_
    192 #endif
    193 
    194 /*
    195 // Because of performane reason hash algorithms are implemented in form
    196 // of unroller cycle and therefore these implementations are big enough.
    197 // Intel(R) IPP supports "compact" implementation of some basic hash algorithms:
    198 //    SHA-1
    199 //    SHA-256
    200 //    SHA-512
    201 //    SM3
    202 //
    203 // Define any
    204 //    _ALG_SHA1_COMPACT_
    205 //    _ALG_SHA256_COMPACT_
    206 //    _ALG_SHA512_COMPACT_
    207 //    _ALG_SM3_COMPACT_
    208 //
    209 // to select "compact" implementation of particular hash algorithm.
    210 // Intel(R) IPP does not define "compact" implementation by default.
    211 //
    212 // Don't know what performance degradation leads "compact"
    213 // in comparison with default Intel(R) IPP implementation.
    214 //
    215 // Note: the definition like _ALG_XXX_COMPACT_ has effect
    216 // if and only if Intel(R) IPP instance is _PX or _MX
    217 */
    218 //#define _ALG_SHA1_COMPACT_
    219 //#define _ALG_SHA256_COMPACT_
    220 //#define _ALG_SHA512_COMPACT_
    221 //#define _ALG_SM3_COMPACT_
    222 //#undef _ALG_SHA1_COMPACT_
    223 //#undef _ALG_SHA256_COMPACT_
    224 //#undef _ALG_SHA512_COMPACT_
    225 //#undef _ALG_SM3_COMPACT_
    226 
    227 
    228 /*
    229 // BN arithmetic:
    230 //    - do/don't use special implementation of sqr instead of usual multication
    231 //    - do/don't use Karatsuba multiplication alg
    232 */
    233 #define _USE_SQR_          /*     use implementaton of sqr */
    234 #if !defined(_DISABLE_WINDOW_EXP_)
    235    #define _USE_WINDOW_EXP_   /*     use fixed window exponentiation */
    236 #endif
    237 
    238 
    239 /*
    240 // RSA:
    241 //    - do/don't use version 1 style mitigation of CBA
    242 //    - do/don't use own style mitigation of CBA
    243 //    - do/don't use Folding technique for RSA-1204 implementation
    244 */
    245 #define xUSE_VERSION1_CBA_MITIGATION_   /* not use (version 1)  mitigation of CBA */
    246 #define _USE_IPP_OWN_CBA_MITIGATION_    /*     use (own) mitigation of CBA */
    247 #define xUSE_FOLD_MONT512_              /*     use folding technique in RSA-1024 case */
    248 
    249 
    250 /*
    251 // Intel(R) IPP supports different implementation of NIST's (standard) EC over GF(0):
    252 //    P-128 (IppECCPStd128r1, IppECCPStd128r2)
    253 //    P-192 (IppECCPStd192r1)
    254 //    P-224 (IppECCPStd224r1)
    255 //    P-256 (IppECCPStd256r1)
    256 //    P-384 (IppECCPStd384r1)
    257 //    P-521 (IppECCPStd521r1)
    258 //
    259 // If one need replace the particular implementation by abritrary one
    260 // assign _ECP_IMP_ARBIRTRARY_ to suitable symbol
    261 //
    262 // _ECP_IMPL_ARBIRTRARY_   means that implementtaion does not use any curve specific,
    263 //                         provide the same (single) code for any type curve
    264 //
    265 // _ECP_IMPL_SPECIFIC_     means that implementation uses specific modular reduction
    266 //                         based on prime structure;
    267 //                         most of NIST's cures (p128, p192, p224, p256, p384, p521) are uses
    268 //                         such kind of reduction procedure;
    269 //                         in contrast with _ECP_IMPL_ARBIRTRARY_ and _ECP_IMPL_MFM_
    270 //                         this type of implementation uses point representation in REGULAR residual
    271 //                         (not Montgometry!!) domain
    272 //
    273 // _ECP_IMPL_MFM_          means that implementation uses "Montgomary Friendly Modulus" (primes);
    274 //                         p256 and sm2 are using such kind of optimization
    275 */
    276 #define _ECP_IMPL_NONE_        0
    277 #define _ECP_IMPL_ARBIRTRARY_  1
    278 #define _ECP_IMPL_SPECIFIC_    2
    279 #define _ECP_IMPL_MFM_         3
    280 
    281 #if !defined(_ECP_112R1_)
    282 #if !defined(_DISABLE_ECP_112R1_)
    283 #  define _ECP_112R1_    _ECP_IMPL_ARBIRTRARY_
    284 #else
    285 #  define _ECP_112R1_    _ECP_IMPL_NONE_
    286 #endif
    287 #endif
    288 
    289 #if !defined(_ECP_112R2_)
    290 #if !defined(_DISABLE_ECP_112R2_)
    291 #  define _ECP_112R2_    _ECP_IMPL_ARBIRTRARY_
    292 #else
    293 #  define _ECP_112R2_    _ECP_IMPL_NONE_
    294 #endif
    295 #endif
    296 
    297 #if !defined(_ECP_160R1_)
    298 #if !defined(_DISABLE_ECP_160R1_)
    299 #  define _ECP_160R1_    _ECP_IMPL_ARBIRTRARY_
    300 #else
    301 #  define _ECP_160R1_    _ECP_IMPL_NONE_
    302 #endif
    303 #endif
    304 
    305 #if !defined(_ECP_160R2_)
    306 #if !defined(_DISABLE_ECP_160R2_)
    307 #  define _ECP_160R2_    _ECP_IMPL_ARBIRTRARY_
    308 #else
    309 #  define _ECP_160R2_    _ECP_IMPL_NONE_
    310 #endif
    311 #endif
    312 
    313 #if !defined(_ECP_128R1_)
    314 #if !defined(_DISABLE_ECP_128R1_)
    315 #  define _ECP_128R1_    _ECP_IMPL_SPECIFIC_
    316 #else
    317 #  define _ECP_128R1_    _ECP_IMPL_NONE_
    318 #endif
    319 #endif
    320 
    321 #if !defined(_ECP_128R2_)
    322 #if !defined(_DISABLE_ECP_128R2_)
    323 #  define _ECP_128R2_    _ECP_IMPL_SPECIFIC_
    324 #else
    325 #  define _ECP_128R2_    _ECP_IMPL_NONE_
    326 #endif
    327 #endif
    328 
    329 #if !defined(_ECP_192_)
    330 #if !defined(_DISABLE_ECP_192_)
    331 #  if (_IPP32E >= _IPP32E_M7) || (_IPP >= _IPP_P8)
    332 #     define _ECP_192_    _ECP_IMPL_MFM_
    333 #  else
    334 #     define _ECP_192_    _ECP_IMPL_SPECIFIC_
    335 #  endif
    336 #else
    337 #  define _ECP_192_    _ECP_IMPL_NONE_
    338 #endif
    339 #endif
    340 
    341 #if !defined(_ECP_224_)
    342 #if !defined(_DISABLE_ECP_224_)
    343 #  if (_IPP32E >= _IPP32E_M7) || (_IPP >= _IPP_P8)
    344 #     define _ECP_224_    _ECP_IMPL_MFM_
    345 #  else
    346 #     define _ECP_224_    _ECP_IMPL_SPECIFIC_
    347 #  endif
    348 #else
    349 #  define _ECP_224_    _ECP_IMPL_NONE_
    350 #endif
    351 #endif
    352 
    353 #if !defined(_ECP_256_)
    354 #if !defined(_DISABLE_ECP_256_)
    355 #  if (_IPP32E >= _IPP32E_M7) || (_IPP >= _IPP_P8)
    356 #     define _ECP_256_    _ECP_IMPL_MFM_
    357 #  else
    358 #     define _ECP_256_    _ECP_IMPL_SPECIFIC_
    359 #  endif
    360 #else
    361 #  define _ECP_256_    _ECP_IMPL_NONE_
    362 #endif
    363 #endif
    364 
    365 #if !defined(_ECP_384_)
    366 #if !defined(_DISABLE_ECP_384_)
    367 #  if (_IPP32E >= _IPP32E_M7) || (_IPP >= _IPP_P8)
    368 #     define _ECP_384_    _ECP_IMPL_MFM_
    369 #  else
    370 #     define _ECP_384_    _ECP_IMPL_SPECIFIC_
    371 #  endif
    372 #else
    373 #  define _ECP_384_    _ECP_IMPL_NONE_
    374 #endif
    375 #endif
    376 
    377 #if !defined(_ECP_521_)
    378 #if !defined(_DISABLE_ECP_521_)
    379 #  if (_IPP32E >= _IPP32E_M7) || (_IPP >= _IPP_P8)
    380 #     define _ECP_521_    _ECP_IMPL_MFM_
    381 #  else
    382 #     define _ECP_521_    _ECP_IMPL_SPECIFIC_
    383 #  endif
    384 #else
    385 #  define _ECP_521_    _ECP_IMPL_NONE_
    386 #endif
    387 #endif
    388 
    389 #if !defined(_ECP_SM2_)
    390 #if !defined(_DISABLE_ECP_SM2_)
    391 #  if (_IPP32E >= _IPP32E_M7) || (_IPP >= _IPP_P8)
    392 #     define _ECP_SM2_    _ECP_IMPL_MFM_
    393 #  else
    394 #     define _ECP_SM2_    _ECP_IMPL_SPECIFIC_
    395 #  endif
    396 #else
    397 #  define _ECP_SM2_    _ECP_IMPL_NONE_
    398 #endif
    399 #endif
    400 
    401 #if !defined(_ECP_BN_)
    402 #if !defined(_DISABLE_ECP_BN_)
    403 #  define _ECP_BN_    _ECP_IMPL_ARBIRTRARY_
    404 #else
    405 #  define _ECP_BN_    _ECP_IMPL_NONE_
    406 #endif
    407 #endif
    408 
    409 #if !defined(_DISABLE_ECP_GENERAL_)
    410 #  define _ECP_GENERAL_ _ECP_IMPL_ARBIRTRARY_
    411 #else
    412 #  define _ECP_GENERAL_ _ECP_IMPL_NONE_
    413 #endif
    414 
    415 
    416 /*
    417 // EC over GF(p):
    418 //    - do/don't use mitigation of CBA
    419 */
    420 #define _USE_ECCP_SSCM_             /*     use SSCM ECCP */
    421 
    422 
    423 #if defined ( _OPENMP )
    424 #define DEFAULT_CPU_NUM    (8)
    425 
    426 #define     BF_MIN_BLK_PER_THREAD (32)
    427 #define     TF_MIN_BLK_PER_THREAD (16)
    428 
    429 #define    DES_MIN_BLK_PER_THREAD (32)
    430 #define   TDES_MIN_BLK_PER_THREAD (16)
    431 
    432 #define  RC5_64_MIN_BLK_PER_THREAD (16)
    433 #define RC5_128_MIN_BLK_PER_THREAD (32)
    434 
    435 #define RIJ128_MIN_BLK_PER_THREAD (32)
    436 #define RIJ192_MIN_BLK_PER_THREAD (16)
    437 #define RIJ256_MIN_BLK_PER_THREAD (16)
    438 
    439 #define AESNI128_MIN_BLK_PER_THREAD (256)
    440 #endif
    441 
    442 #endif /* _CP_VARIANT_H */
    443