ippcpdefs.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /*############################################################################
  2. # Copyright 2016 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. // Intel(R) Integrated Performance Primitives
  18. // Cryptographic Primitives (ippCP) definitions.
  19. //
  20. //
  21. */
  22. #ifndef __IPPCPDEFS_H__
  23. #define __IPPCPDEFS_H__
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #if !defined( _OWN_BLDPCS )
  28. typedef Ipp32u IppAlgId;
  29. /*
  30. // =========================================================
  31. // Symmetric Ciphers
  32. // =========================================================
  33. */
  34. typedef enum {
  35. ippPaddingNONE = 0, /*NONE = 0,*/ IppsCPPaddingNONE = 0,
  36. ippPaddingPKCS7 = 1, /*PKCS7 = 1,*/ IppsCPPaddingPKCS7 = 1,
  37. ippPaddingZEROS = 2, /*ZEROS = 2,*/ IppsCPPaddingZEROS = 2
  38. } IppsPadding, IppsCPPadding;
  39. typedef struct _cpDES IppsDESSpec;
  40. typedef struct _cpRijndael128 IppsAESSpec;
  41. typedef struct _cpRijndael128 IppsRijndael128Spec;
  42. typedef struct _cpSMS4 IppsSMS4Spec;
  43. /* TDES */
  44. #define DES_BLOCKSIZE (64) /* cipher blocksize (bits) */
  45. #define TDES_BLOCKSIZE DES_BLOCKSIZE
  46. #define DES_KEYSIZE (64) /* cipher keysize (bits) */
  47. #define TDES_KEYSIZE DES_KEYSIZE
  48. /* AES */
  49. #define IPP_AES_BLOCK_BITSIZE (128) /* cipher blocksizes (bits) */
  50. /* Rijndael */
  51. typedef enum {
  52. ippRijndaelKey128 = 128, IppsRijndaelKey128 = 128, /* 128-bit key */
  53. ippRijndaelKey192 = 192, IppsRijndaelKey192 = 192, /* 192-bit key */
  54. ippRijndaelKey256 = 256, IppsRijndaelKey256 = 256 /* 256-bit key */
  55. } IppsRijndaelKeyLength;
  56. /* AES based authentication & confidence */
  57. typedef struct _cpRijndael128GCM IppsRijndael128GCMState;
  58. typedef struct _cpAES_CCM IppsAES_CCMState;
  59. typedef struct _cpRijndael128GCM IppsAES_GCMState;
  60. /*
  61. // =========================================================
  62. // ARCFOUR Stream Cipher
  63. // =========================================================
  64. */
  65. typedef struct _cpARCfour IppsARCFourState;
  66. #define IPP_ARCFOUR_KEYMAX_SIZE (256) /* max key length (bytes) */
  67. #define MAX_ARCFOUR_KEY_LEN IPP_ARCFOUR_KEYMAX_SIZE /* obsolete */
  68. /*
  69. // =========================================================
  70. // One-Way Hash Functions
  71. // =========================================================
  72. */
  73. typedef enum {
  74. ippHashAlg_Unknown,
  75. ippHashAlg_SHA1,
  76. ippHashAlg_SHA256,
  77. ippHashAlg_SHA224,
  78. ippHashAlg_SHA512,
  79. ippHashAlg_SHA384,
  80. ippHashAlg_MD5,
  81. ippHashAlg_SM3,
  82. ippHashAlg_SHA512_224,
  83. ippHashAlg_SHA512_256,
  84. ippHashAlg_MaxNo
  85. } IppHashAlgId;
  86. #define IPP_ALG_HASH_UNKNOWN (ippHashAlg_Unknown) /* unknown */
  87. #define IPP_ALG_HASH_SHA1 (ippHashAlg_SHA1) /* SHA1 */
  88. #define IPP_ALG_HASH_SHA256 (ippHashAlg_SHA256) /* SHA256 */
  89. #define IPP_ALG_HASH_SHA224 (ippHashAlg_SHA224) /* SHA224 or SHA256/224 */
  90. #define IPP_ALG_HASH_SHA512 (ippHashAlg_SHA512) /* SHA512 */
  91. #define IPP_ALG_HASH_SHA384 (ippHashAlg_SHA384) /* SHA384 or SHA512/384 */
  92. #define IPP_ALG_HASH_MD5 (ippHashAlg_MD5) /* MD5 */
  93. #define IPP_ALG_HASH_SM3 (ippHashAlg_SM3) /* SM3 */
  94. #define IPP_ALG_HASH_SHA512_224 (ippHashAlg_SHA512_224) /* SHA512/224 */
  95. #define IPP_ALG_HASH_SHA512_256 (ippHashAlg_SHA512_256) /* SHA512/256 */
  96. #define IPP_ALG_HASH_LIMIT (ippHashAlg_MaxNo) /* hash alg limiter*/
  97. typedef struct _cpSHA1 IppsSHA1State;
  98. typedef struct _cpSHA256 IppsSHA256State;
  99. typedef struct _cpSHA256 IppsSHA224State;
  100. typedef struct _cpSHA512 IppsSHA512State;
  101. typedef struct _cpSHA512 IppsSHA384State;
  102. typedef struct _cpMD5 IppsMD5State;
  103. typedef struct _cpSM3 IppsSM3State;
  104. typedef struct _cpHashCtx IppsHashState;
  105. /* MGF */
  106. typedef IppStatus (__STDCALL *IppMGF)(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen);
  107. /* HASH function */
  108. typedef IppStatus (__STDCALL *IppHASH)(const Ipp8u* pMsg, int len, Ipp8u* pMD);
  109. #define IPP_SHA1_DIGEST_BITSIZE 160 /* digest size (bits) */
  110. #define IPP_SHA256_DIGEST_BITSIZE 256
  111. #define IPP_SHA224_DIGEST_BITSIZE 224
  112. #define IPP_SHA384_DIGEST_BITSIZE 384
  113. #define IPP_SHA512_DIGEST_BITSIZE 512
  114. #define IPP_MD5_DIGEST_BITSIZE 128
  115. #define IPP_SM3_DIGEST_BITSIZE 256
  116. #define IPP_SHA512_224_DIGEST_BITSIZE 224
  117. #define IPP_SHA512_256_DIGEST_BITSIZE 256
  118. /*
  119. // =========================================================
  120. // Keyed-Hash Message Authentication Codes
  121. // =========================================================
  122. */
  123. typedef struct _cpHMAC IppsHMACState;
  124. typedef struct _cpHMAC IppsHMACSHA1State;
  125. typedef struct _cpHMAC IppsHMACSHA256State;
  126. typedef struct _cpHMAC IppsHMACSHA224State;
  127. typedef struct _cpHMAC IppsHMACSHA384State;
  128. typedef struct _cpHMAC IppsHMACSHA512State;
  129. typedef struct _cpHMAC IppsHMACMD5State;
  130. /*
  131. // =========================================================
  132. // Data Authentication Codes
  133. // =========================================================
  134. */
  135. typedef struct _cpAES_CMAC IppsAES_CMACState;
  136. /*
  137. // =========================================================
  138. // Big Number Integer Arithmetic
  139. // =========================================================
  140. */
  141. typedef enum {
  142. ippBigNumNEG = 0, IppsBigNumNEG = 0,
  143. ippBigNumPOS = 1, IppsBigNumPOS = 1
  144. } IppsBigNumSGN;
  145. typedef enum {
  146. ippBinaryMethod = 0, IppsBinaryMethod = 0,
  147. ippSlidingWindows = 1, IppsSlidingWindows = 1
  148. } IppsExpMethod;
  149. typedef struct _cpBigNum IppsBigNumState;
  150. typedef struct _cpMontgomery IppsMontState;
  151. typedef struct _cpPRNG IppsPRNGState;
  152. typedef struct _cpPrime IppsPrimeState;
  153. /* External Bit Supplier */
  154. typedef IppStatus (__STDCALL *IppBitSupplier)(Ipp32u* pRand, int nBits, void* pEbsParams);
  155. #define IPP_IS_EQ (0)
  156. #define IPP_IS_GT (1)
  157. #define IPP_IS_LT (2)
  158. #define IPP_IS_NE (3)
  159. #define IPP_IS_NA (4)
  160. #define IPP_IS_PRIME (5)
  161. #define IPP_IS_COMPOSITE (6)
  162. #define IPP_IS_VALID (7)
  163. #define IPP_IS_INVALID (8)
  164. #define IPP_IS_INCOMPLETE (9)
  165. #define IPP_IS_ATINFINITY (10)
  166. #define IS_ZERO IPP_IS_EQ
  167. #define GREATER_THAN_ZERO IPP_IS_GT
  168. #define LESS_THAN_ZERO IPP_IS_LT
  169. #define IS_PRIME IPP_IS_PRIME
  170. #define IS_COMPOSITE IPP_IS_COMPOSITE
  171. #define IS_VALID_KEY IPP_IS_VALID
  172. #define IS_INVALID_KEY IPP_IS_INVALID
  173. #define IS_INCOMPLETED_KEY IPP_IS_INCOMPLETE
  174. /*
  175. // =========================================================
  176. // RSA Cryptography
  177. // =========================================================
  178. */
  179. typedef struct _cpRSA IppsRSAState;
  180. /* key types */
  181. typedef enum {
  182. ippRSApublic = 0x20000000, IppRSApublic = 0x20000000,
  183. ippRSAprivate = 0x40000000, IppRSAprivate = 0x40000000
  184. } IppRSAKeyType;
  185. /* key component's tag */
  186. typedef enum {
  187. ippRSAkeyN = 0x01, IppRSAkeyN = 0x01,
  188. ippRSAkeyE = 0x02, IppRSAkeyE = 0x02,
  189. ippRSAkeyD = 0x04, IppRSAkeyD = 0x04,
  190. ippRSAkeyP = 0x08, IppRSAkeyP = 0x08,
  191. ippRSAkeyQ = 0x10, IppRSAkeyQ = 0x10,
  192. ippRSAkeyDp = 0x20, IppRSAkeyDp = 0x20,
  193. ippRSAkeyDq = 0x40, IppRSAkeyDq = 0x40,
  194. ippRSAkeyQinv = 0x80, IppRSAkeyQinv = 0x80
  195. } IppRSAKeyTag;
  196. typedef struct _cpRSA_public_key IppsRSAPublicKeyState;
  197. typedef struct _cpRSA_private_key IppsRSAPrivateKeyState;
  198. #define MIN_RSA_SIZE (8)
  199. #define MAX_RSA_SIZE (4096)
  200. /*
  201. // =========================================================
  202. // DL Cryptography
  203. // =========================================================
  204. */
  205. typedef struct _cpDLP IppsDLPState;
  206. /* domain parameter tags */
  207. typedef enum {
  208. ippDLPkeyP = 0x01, IppDLPkeyP = 0x01,
  209. ippDLPkeyR = 0x02, IppDLPkeyR = 0x02,
  210. ippDLPkeyG = 0x04, IppDLPkeyG = 0x04
  211. } IppDLPKeyTag;
  212. typedef enum {
  213. ippDLValid, /* validation pass successfully */
  214. ippDLBaseIsEven, /* !(P is odd) */
  215. ippDLOrderIsEven, /* !(R is odd) */
  216. ippDLInvalidBaseRange, /* !(2^(L-1) < P < 2^L) */
  217. ippDLInvalidOrderRange, /* !(2^(M-1) < R < 2^M) */
  218. ippDLCompositeBase,
  219. ippDLCompositeOrder,
  220. ippDLInvalidCofactor, /* !( R|(P-1) ) */
  221. ippDLInvalidGenerator, /* !( G^R == 1 (mod P) ) */
  222. /* !(1 < G < (P-1)) */
  223. ippDLInvalidPrivateKey, /* !(1 < private < (R-1)) */
  224. ippDLInvalidPublicKey, /* !(1 < public <=(P-1)) */
  225. ippDLInvalidKeyPair, /* !(G^private == public */
  226. ippDLInvalidSignature /* invalid signature */
  227. } IppDLResult;
  228. #define MIN_DLP_BITSIZE (512)
  229. #define MIN_DLP_BITSIZER (160)
  230. #define MIN_DLPDH_BITSIZE (512)
  231. #define MIN_DLPDH_BITSIZER (160)
  232. #define DEF_DLPDH_BITSIZER (160)
  233. #define MIN_DLPDSA_BITSIZE (512)
  234. #define MAX_DLPDSA_BITSIZE (1024)
  235. #define MIN_DLPDSA_BITSIZER (160)
  236. #define DEF_DLPDSA_BITSIZER (160)
  237. #define MAX_DLPDSA_BITSIZER (160)
  238. #define MIN_DLPDSA_SEEDSIZE (160)
  239. /*
  240. // =========================================================
  241. // EC Cryptography
  242. // =========================================================
  243. */
  244. typedef struct _cpECCP IppsECCPState;
  245. typedef struct _cpECCB IppsECCBState;
  246. typedef struct _cpECCPPoint IppsECCPPointState;
  247. typedef struct _cpECCBPoint IppsECCBPointState;
  248. /* operation result */
  249. typedef enum {
  250. ippECValid, /* validation pass successfully */
  251. ippECCompositeBase, /* field based on composite */
  252. ippECComplicatedBase, /* number of non-zero terms in the polynomial (> PRIME_ARR_MAX) */
  253. ippECIsZeroDiscriminant,/* zero discriminant */
  254. ippECCompositeOrder, /* composite order of base point */
  255. ippECInvalidOrder, /* invalid base point order */
  256. ippECIsWeakMOV, /* weak Meneze-Okamoto-Vanstone reduction attack */
  257. ippECIsWeakSSSA, /* weak Semaev-Smart,Satoh-Araki reduction attack */
  258. ippECIsSupersingular, /* supersingular curve */
  259. ippECInvalidPrivateKey, /* !(0 < Private < order) */
  260. ippECInvalidPublicKey, /* (order*PublicKey != Infinity) */
  261. ippECInvalidKeyPair, /* (Private*BasePoint != PublicKey) */
  262. ippECPointOutOfGroup, /* out of group (order*P != Infinity) */
  263. ippECPointIsAtInfinite, /* point (P=(Px,Py)) at Infinity */
  264. ippECPointIsNotValid, /* point (P=(Px,Py)) out-of EC */
  265. ippECPointIsEqual, /* compared points are equal */
  266. ippECPointIsNotEqual, /* compared points are different */
  267. ippECInvalidSignature /* invalid signature */
  268. } IppECResult;
  269. /* domain parameter set/get flags */
  270. typedef enum {
  271. ippECarbitrary =0x00000, IppECCArbitrary = 0x00000, /* arbitrary ECC */
  272. ippECPstd = 0x10000, IppECCPStd = 0x10000, /* random (recommended) EC over FG(p): */
  273. ippECPstd112r1 = ippECPstd, IppECCPStd112r1 = IppECCPStd, /* secp112r1 curve */
  274. ippECPstd112r2 = ippECPstd+1, IppECCPStd112r2 = IppECCPStd+1, /* secp112r2 curve */
  275. ippECPstd128r1 = ippECPstd+2, IppECCPStd128r1 = IppECCPStd+2, /* secp128r1 curve */
  276. ippECPstd128r2 = ippECPstd+3, IppECCPStd128r2 = IppECCPStd+3, /* secp128r2 curve */
  277. ippECPstd160r1 = ippECPstd+4, IppECCPStd160r1 = IppECCPStd+4, /* secp160r1 curve */
  278. ippECPstd160r2 = ippECPstd+5, IppECCPStd160r2 = IppECCPStd+5, /* secp160r2 curve */
  279. ippECPstd192r1 = ippECPstd+6, IppECCPStd192r1 = IppECCPStd+6, /* secp192r1 curve */
  280. ippECPstd224r1 = ippECPstd+7, IppECCPStd224r1 = IppECCPStd+7, /* secp224r1 curve */
  281. ippECPstd256r1 = ippECPstd+8, IppECCPStd256r1 = IppECCPStd+8, /* secp256r1 curve */
  282. ippECPstd384r1 = ippECPstd+9, IppECCPStd384r1 = IppECCPStd+9, /* secp384r1 curve */
  283. ippECPstd521r1 = ippECPstd+10, IppECCPStd521r1 = IppECCPStd+10, /* secp521r1 curve */
  284. ippECPstdSM2 = ippECPstd+11, IppECCPStdSM2 = IppECCPStd+11, /* TMP SM2 curve */
  285. ippEC_TPM_SM2_P256= ippECPstd+11,
  286. ippEC_TPM_BN_P256 = ippECPstd+12, /* TPM BN_P256 curve */
  287. /* curves over binary finit fields are not supported in IPP 9.0 */
  288. IppECCBStd = 0x20000, /* random (recommended) EC over FG(2^m): */
  289. IppECCBStd113r1 = IppECCBStd, /* sect113r1 curve */
  290. IppECCBStd113r2 = IppECCBStd+1, /* sect113r2 curve */
  291. IppECCBStd131r1 = IppECCBStd+2, /* sect131r1 curve */
  292. IppECCBStd131r2 = IppECCBStd+3, /* sect131r2 curve */
  293. IppECCBStd163r1 = IppECCBStd+4, /* sect163r1 curve */
  294. IppECCBStd163r2 = IppECCBStd+5, /* sect163r2 curve */
  295. IppECCBStd193r1 = IppECCBStd+6, /* sect193r1 curve */
  296. IppECCBStd193r2 = IppECCBStd+7, /* sect193r2 curve */
  297. IppECCBStd233r1 = IppECCBStd+8, /* sect233r1 curve */
  298. IppECCBStd283r1 = IppECCBStd+9, /* sect283r1 curve */
  299. IppECCBStd409r1 = IppECCBStd+10, /* sect409r1 curve */
  300. IppECCBStd571r1 = IppECCBStd+11, /* sect571r1 curve */
  301. IppECCKStd = 0x40000, /* Koblitz (recommended) EC over FG(2^m): */
  302. IppECCBStd163k1 = IppECCKStd, /* Koblitz 163 curve */
  303. IppECCBStd233k1 = IppECCKStd+1, /* Koblitz 233 curve */
  304. IppECCBStd239k1 = IppECCKStd+2, /* Koblitz 239 curve */
  305. IppECCBStd283k1 = IppECCKStd+3, /* Koblitz 283 curve */
  306. IppECCBStd409k1 = IppECCKStd+4, /* Koblitz 409 curve */
  307. IppECCBStd571k1 = IppECCKStd+5 /* Koblitz 571 curve */
  308. } IppsECType, IppECCType;
  309. #endif /* _OWN_BLDPCS */
  310. #ifdef __cplusplus
  311. }
  312. #endif
  313. #endif /* __IPPCPDEFS_H__ */