Xuyi Wang / wolfSSL

Dependents:   OS

Committer:
wolfSSL
Date:
Tue May 02 08:44:47 2017 +0000
Revision:
7:481bce714567
wolfSSL3.10.2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 7:481bce714567 1 /* des3.h
wolfSSL 7:481bce714567 2 *
wolfSSL 7:481bce714567 3 * Copyright (C) 2006-2016 wolfSSL Inc.
wolfSSL 7:481bce714567 4 *
wolfSSL 7:481bce714567 5 * This file is part of wolfSSL.
wolfSSL 7:481bce714567 6 *
wolfSSL 7:481bce714567 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 7:481bce714567 8 * it under the terms of the GNU General Public License as published by
wolfSSL 7:481bce714567 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 7:481bce714567 10 * (at your option) any later version.
wolfSSL 7:481bce714567 11 *
wolfSSL 7:481bce714567 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 7:481bce714567 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 7:481bce714567 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 7:481bce714567 15 * GNU General Public License for more details.
wolfSSL 7:481bce714567 16 *
wolfSSL 7:481bce714567 17 * You should have received a copy of the GNU General Public License
wolfSSL 7:481bce714567 18 * along with this program; if not, write to the Free Software
wolfSSL 7:481bce714567 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 7:481bce714567 20 */
wolfSSL 7:481bce714567 21
wolfSSL 7:481bce714567 22
wolfSSL 7:481bce714567 23 #ifndef WOLF_CRYPT_DES3_H
wolfSSL 7:481bce714567 24 #define WOLF_CRYPT_DES3_H
wolfSSL 7:481bce714567 25
wolfSSL 7:481bce714567 26 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 7:481bce714567 27
wolfSSL 7:481bce714567 28 #ifndef NO_DES3
wolfSSL 7:481bce714567 29
wolfSSL 7:481bce714567 30 #ifdef HAVE_FIPS
wolfSSL 7:481bce714567 31 /* included for fips @wc_fips */
wolfSSL 7:481bce714567 32 #include <cyassl/ctaocrypt/des3.h>
wolfSSL 7:481bce714567 33 #endif
wolfSSL 7:481bce714567 34
wolfSSL 7:481bce714567 35 #ifdef __cplusplus
wolfSSL 7:481bce714567 36 extern "C" {
wolfSSL 7:481bce714567 37 #endif
wolfSSL 7:481bce714567 38
wolfSSL 7:481bce714567 39 #ifndef HAVE_FIPS /* to avoid redefinition of macros */
wolfSSL 7:481bce714567 40
wolfSSL 7:481bce714567 41 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 7:481bce714567 42 #include <wolfssl/wolfcrypt/async.h>
wolfSSL 7:481bce714567 43 #endif
wolfSSL 7:481bce714567 44
wolfSSL 7:481bce714567 45 enum {
wolfSSL 7:481bce714567 46 DES_ENC_TYPE = 2, /* cipher unique type */
wolfSSL 7:481bce714567 47 DES3_ENC_TYPE = 3, /* cipher unique type */
wolfSSL 7:481bce714567 48 DES_BLOCK_SIZE = 8,
wolfSSL 7:481bce714567 49 DES_KS_SIZE = 32,
wolfSSL 7:481bce714567 50
wolfSSL 7:481bce714567 51 DES_ENCRYPTION = 0,
wolfSSL 7:481bce714567 52 DES_DECRYPTION = 1
wolfSSL 7:481bce714567 53 };
wolfSSL 7:481bce714567 54
wolfSSL 7:481bce714567 55 #define DES_IVLEN 8
wolfSSL 7:481bce714567 56 #define DES_KEYLEN 8
wolfSSL 7:481bce714567 57 #define DES3_IVLEN 8
wolfSSL 7:481bce714567 58 #define DES3_KEYLEN 24
wolfSSL 7:481bce714567 59
wolfSSL 7:481bce714567 60
wolfSSL 7:481bce714567 61 #if defined(STM32F2_CRYPTO) || defined(STM32F4_CRYPTO)
wolfSSL 7:481bce714567 62 enum {
wolfSSL 7:481bce714567 63 DES_CBC = 0,
wolfSSL 7:481bce714567 64 DES_ECB = 1
wolfSSL 7:481bce714567 65 };
wolfSSL 7:481bce714567 66 #endif
wolfSSL 7:481bce714567 67
wolfSSL 7:481bce714567 68
wolfSSL 7:481bce714567 69 /* DES encryption and decryption */
wolfSSL 7:481bce714567 70 typedef struct Des {
wolfSSL 7:481bce714567 71 word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
wolfSSL 7:481bce714567 72 word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */
wolfSSL 7:481bce714567 73 word32 key[DES_KS_SIZE];
wolfSSL 7:481bce714567 74 } Des;
wolfSSL 7:481bce714567 75
wolfSSL 7:481bce714567 76
wolfSSL 7:481bce714567 77 /* DES3 encryption and decryption */
wolfSSL 7:481bce714567 78 typedef struct Des3 {
wolfSSL 7:481bce714567 79 word32 key[3][DES_KS_SIZE];
wolfSSL 7:481bce714567 80 word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
wolfSSL 7:481bce714567 81 word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */
wolfSSL 7:481bce714567 82 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 7:481bce714567 83 AsyncCryptDev asyncDev;
wolfSSL 7:481bce714567 84 #endif
wolfSSL 7:481bce714567 85 } Des3;
wolfSSL 7:481bce714567 86 #endif /* HAVE_FIPS */
wolfSSL 7:481bce714567 87
wolfSSL 7:481bce714567 88 WOLFSSL_API int wc_Des_SetKey(Des* des, const byte* key,
wolfSSL 7:481bce714567 89 const byte* iv, int dir);
wolfSSL 7:481bce714567 90 WOLFSSL_API void wc_Des_SetIV(Des* des, const byte* iv);
wolfSSL 7:481bce714567 91 WOLFSSL_API int wc_Des_CbcEncrypt(Des* des, byte* out,
wolfSSL 7:481bce714567 92 const byte* in, word32 sz);
wolfSSL 7:481bce714567 93 WOLFSSL_API int wc_Des_CbcDecrypt(Des* des, byte* out,
wolfSSL 7:481bce714567 94 const byte* in, word32 sz);
wolfSSL 7:481bce714567 95 WOLFSSL_API int wc_Des_EcbEncrypt(Des* des, byte* out,
wolfSSL 7:481bce714567 96 const byte* in, word32 sz);
wolfSSL 7:481bce714567 97 WOLFSSL_API int wc_Des3_EcbEncrypt(Des3* des, byte* out,
wolfSSL 7:481bce714567 98 const byte* in, word32 sz);
wolfSSL 7:481bce714567 99
wolfSSL 7:481bce714567 100 /* ECB decrypt same process as encrypt but with decrypt key */
wolfSSL 7:481bce714567 101 #define wc_Des_EcbDecrypt wc_Des_EcbEncrypt
wolfSSL 7:481bce714567 102 #define wc_Des3_EcbDecrypt wc_Des3_EcbEncrypt
wolfSSL 7:481bce714567 103
wolfSSL 7:481bce714567 104 WOLFSSL_API int wc_Des3_SetKey(Des3* des, const byte* key,
wolfSSL 7:481bce714567 105 const byte* iv,int dir);
wolfSSL 7:481bce714567 106 WOLFSSL_API int wc_Des3_SetIV(Des3* des, const byte* iv);
wolfSSL 7:481bce714567 107 WOLFSSL_API int wc_Des3_CbcEncrypt(Des3* des, byte* out,
wolfSSL 7:481bce714567 108 const byte* in,word32 sz);
wolfSSL 7:481bce714567 109 WOLFSSL_API int wc_Des3_CbcDecrypt(Des3* des, byte* out,
wolfSSL 7:481bce714567 110 const byte* in,word32 sz);
wolfSSL 7:481bce714567 111
wolfSSL 7:481bce714567 112 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 7:481bce714567 113 WOLFSSL_API int wc_Des3AsyncInit(Des3*, int);
wolfSSL 7:481bce714567 114 WOLFSSL_API void wc_Des3AsyncFree(Des3*);
wolfSSL 7:481bce714567 115 #endif
wolfSSL 7:481bce714567 116
wolfSSL 7:481bce714567 117 #ifdef __cplusplus
wolfSSL 7:481bce714567 118 } /* extern "C" */
wolfSSL 7:481bce714567 119 #endif
wolfSSL 7:481bce714567 120
wolfSSL 7:481bce714567 121 #endif /* NO_DES3 */
wolfSSL 7:481bce714567 122 #endif /* WOLF_CRYPT_DES3_H */
wolfSSL 7:481bce714567 123
wolfSSL 7:481bce714567 124