]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/WolfSSL/cyassl/ctaocrypt/des3.h
Rename the CyaSSL directory to WolfSSL
[freertos] / FreeRTOS-Plus / Source / WolfSSL / cyassl / ctaocrypt / des3.h
1 /* des3.h
2  *
3  * Copyright (C) 2006-2014 wolfSSL Inc.
4  *
5  * This file is part of CyaSSL.
6  *
7  * CyaSSL is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * CyaSSL is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22
23 #ifndef NO_DES3
24
25 #ifndef CTAO_CRYPT_DES3_H
26 #define CTAO_CRYPT_DES3_H
27
28
29 #include <cyassl/ctaocrypt/types.h>
30
31
32 #ifdef __cplusplus
33     extern "C" {
34 #endif
35
36 #define CYASSL_3DES_CAVIUM_MAGIC 0xBEEF0003
37
38 enum {
39     DES_ENC_TYPE    = 2,     /* cipher unique type */
40     DES3_ENC_TYPE   = 3,     /* cipher unique type */
41     DES_BLOCK_SIZE  = 8,
42     DES_KS_SIZE     = 32,
43
44     DES_ENCRYPTION  = 0,
45     DES_DECRYPTION  = 1
46 };
47
48 #define DES_IVLEN 8
49 #define DES_KEYLEN 8
50 #define DES3_IVLEN 8
51 #define DES3_KEYLEN 24
52
53
54 #ifdef STM32F2_CRYPTO
55 enum {
56     DES_CBC = 0,
57     DES_ECB = 1
58 };
59 #endif
60
61
62 /* DES encryption and decryption */
63 typedef struct Des {
64     word32 reg[DES_BLOCK_SIZE / sizeof(word32)];      /* for CBC mode */
65     word32 tmp[DES_BLOCK_SIZE / sizeof(word32)];      /* same         */
66     word32 key[DES_KS_SIZE];
67 } Des;
68
69
70 /* DES3 encryption and decryption */
71 typedef struct Des3 {
72     word32 key[3][DES_KS_SIZE];
73     word32 reg[DES_BLOCK_SIZE / sizeof(word32)];      /* for CBC mode */
74     word32 tmp[DES_BLOCK_SIZE / sizeof(word32)];      /* same         */
75 #ifdef HAVE_CAVIUM
76     int     devId;           /* nitrox device id */
77     word32  magic;           /* using cavium magic */
78     word64  contextHandle;   /* nitrox context memory handle */
79 #endif
80 } Des3;
81
82
83 CYASSL_API int  Des_SetKey(Des* des, const byte* key, const byte* iv, int dir);
84 CYASSL_API void Des_SetIV(Des* des, const byte* iv);
85 CYASSL_API int  Des_CbcEncrypt(Des* des, byte* out, const byte* in, word32 sz);
86 CYASSL_API int  Des_CbcDecrypt(Des* des, byte* out, const byte* in, word32 sz);
87 CYASSL_API int  Des_EcbEncrypt(Des* des, byte* out, const byte* in, word32 sz);
88
89 CYASSL_API int  Des3_SetKey(Des3* des, const byte* key, const byte* iv,int dir);
90 CYASSL_API int  Des3_SetIV(Des3* des, const byte* iv);
91 CYASSL_API int  Des3_CbcEncrypt(Des3* des, byte* out, const byte* in,word32 sz);
92 CYASSL_API int  Des3_CbcDecrypt(Des3* des, byte* out, const byte* in,word32 sz);
93
94
95 #ifdef HAVE_CAVIUM
96     CYASSL_API int  Des3_InitCavium(Des3*, int);
97     CYASSL_API void Des3_FreeCavium(Des3*);
98 #endif
99
100
101 #ifdef HAVE_FIPS
102     /* fips wrapper calls, user can call direct */
103     CYASSL_API int  Des3_SetKey_fips(Des3* des, const byte* key, const byte* iv,
104                                      int dir);
105     CYASSL_API int  Des3_SetIV_fips(Des3* des, const byte* iv);
106     CYASSL_API int  Des3_CbcEncrypt_fips(Des3* des, byte* out, const byte* in,
107                                          word32 sz);
108     CYASSL_API int  Des3_CbcDecrypt_fips(Des3* des, byte* out, const byte* in,
109                                          word32 sz);
110     #ifndef FIPS_NO_WRAPPERS
111         /* if not impl or fips.c impl wrapper force fips calls if fips build */
112         #define Des3_SetKey     Des3_SetKey_fips
113         #define Des3_SetIV      Des3_SetIV_fips
114         #define Des3_CbcEncrypt Des3_CbcEncrypt_fips
115         #define Des3_CbcDecrypt Des3_CbcDecrypt_fips
116     #endif /* FIPS_NO_WRAPPERS */
117
118 #endif /* HAVE_FIPS */
119
120
121 #ifdef __cplusplus
122     } /* extern "C" */
123 #endif
124
125 #endif /* NO_DES3 */
126 #endif /* CTAO_CRYPT_DES3_H */
127