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