wolf SSL / wolfSSL-TLS13-Beta

Fork of wolfSSL by wolf SSL

Committer:
wolfSSL
Date:
Fri Jun 26 00:39:20 2015 +0000
Revision:
0:d92f9d21154c
wolfSSL 3.6.0

Who changed what in which revision?

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