source: asp3_tinet_ecnl_rx/trunk/wolfssl-3.12.2/wolfssl/wolfcrypt/des3.h@ 337

Last change on this file since 337 was 337, checked in by coas-nagasima, 6 years ago

ASP3版ECNLを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 3.7 KB
Line 
1/* des3.h
2 *
3 * Copyright (C) 2006-2017 wolfSSL Inc.
4 *
5 * This file is part of wolfSSL.
6 *
7 * wolfSSL 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 * wolfSSL 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-1335, USA
20 */
21
22
23#ifndef WOLF_CRYPT_DES3_H
24#define WOLF_CRYPT_DES3_H
25
26#include <wolfssl/wolfcrypt/types.h>
27
28#ifndef NO_DES3
29
30#ifdef HAVE_FIPS
31/* included for fips @wc_fips */
32#include <cyassl/ctaocrypt/des3.h>
33#endif
34
35#ifdef __cplusplus
36 extern "C" {
37#endif
38
39#ifndef HAVE_FIPS /* to avoid redefinition of macros */
40
41#ifdef WOLFSSL_ASYNC_CRYPT
42 #include <wolfssl/wolfcrypt/async.h>
43#endif
44
45enum {
46 DES_ENC_TYPE = 2, /* cipher unique type */
47 DES3_ENC_TYPE = 3, /* cipher unique type */
48 DES_BLOCK_SIZE = 8,
49 DES_KS_SIZE = 32,
50
51 DES_ENCRYPTION = 0,
52 DES_DECRYPTION = 1
53};
54
55#define DES_IVLEN 8
56#define DES_KEYLEN 8
57#define DES3_IVLEN 8
58#define DES3_KEYLEN 24
59
60
61#if defined(STM32_CRYPTO)
62enum {
63 DES_CBC = 0,
64 DES_ECB = 1
65};
66#endif
67
68
69/* DES encryption and decryption */
70typedef struct Des {
71 word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
72 word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */
73 word32 key[DES_KS_SIZE];
74} Des;
75
76
77/* DES3 encryption and decryption */
78typedef struct Des3 {
79 word32 key[3][DES_KS_SIZE];
80 word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
81 word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */
82#ifdef WOLFSSL_ASYNC_CRYPT
83 const byte* key_raw;
84 const byte* iv_raw;
85 WC_ASYNC_DEV asyncDev;
86#endif
87 void* heap;
88} Des3;
89#endif /* HAVE_FIPS */
90
91
92WOLFSSL_API int wc_Des_SetKey(Des* des, const byte* key,
93 const byte* iv, int dir);
94WOLFSSL_API void wc_Des_SetIV(Des* des, const byte* iv);
95WOLFSSL_API int wc_Des_CbcEncrypt(Des* des, byte* out,
96 const byte* in, word32 sz);
97WOLFSSL_API int wc_Des_CbcDecrypt(Des* des, byte* out,
98 const byte* in, word32 sz);
99WOLFSSL_API int wc_Des_EcbEncrypt(Des* des, byte* out,
100 const byte* in, word32 sz);
101WOLFSSL_API int wc_Des3_EcbEncrypt(Des3* des, byte* out,
102 const byte* in, word32 sz);
103
104/* ECB decrypt same process as encrypt but with decrypt key */
105#define wc_Des_EcbDecrypt wc_Des_EcbEncrypt
106#define wc_Des3_EcbDecrypt wc_Des3_EcbEncrypt
107
108WOLFSSL_API int wc_Des3_SetKey(Des3* des, const byte* key,
109 const byte* iv,int dir);
110WOLFSSL_API int wc_Des3_SetIV(Des3* des, const byte* iv);
111WOLFSSL_API int wc_Des3_CbcEncrypt(Des3* des, byte* out,
112 const byte* in,word32 sz);
113WOLFSSL_API int wc_Des3_CbcDecrypt(Des3* des, byte* out,
114 const byte* in,word32 sz);
115
116/* These are only required when using either:
117 static memory (WOLFSSL_STATIC_MEMORY) or asynchronous (WOLFSSL_ASYNC_CRYPT) */
118WOLFSSL_API int wc_Des3Init(Des3*, void*, int);
119WOLFSSL_API void wc_Des3Free(Des3*);
120
121#ifdef __cplusplus
122 } /* extern "C" */
123#endif
124
125#endif /* NO_DES3 */
126#endif /* WOLF_CRYPT_DES3_H */
127
Note: See TracBrowser for help on using the repository browser.