Renesas / SecureDweet
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers des3.h Source File

des3.h

00001 /* des3.h
00002  *
00003  * Copyright (C) 2006-2016 wolfSSL Inc.
00004  *
00005  * This file is part of wolfSSL.
00006  *
00007  * wolfSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * wolfSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
00020  */
00021 
00022 
00023 #ifndef WOLF_CRYPT_DES3_H
00024 #define WOLF_CRYPT_DES3_H
00025 
00026 #include <wolfssl/wolfcrypt/types.h>
00027 
00028 #ifndef NO_DES3
00029 
00030 #ifdef HAVE_FIPS
00031 /* included for fips @wc_fips */
00032 #include <cyassl/ctaocrypt/des3.h>
00033 #endif
00034 
00035 #ifdef __cplusplus
00036     extern "C" {
00037 #endif
00038 
00039 #ifndef HAVE_FIPS /* to avoid redefinition of macros */
00040 #define WOLFSSL_3DES_CAVIUM_MAGIC 0xBEEF0003
00041 
00042 enum {
00043     DES_ENC_TYPE    = 2,     /* cipher unique type */
00044     DES3_ENC_TYPE   = 3,     /* cipher unique type */
00045     DES_BLOCK_SIZE  = 8,
00046     DES_KS_SIZE     = 32,
00047 
00048     DES_ENCRYPTION  = 0,
00049     DES_DECRYPTION  = 1
00050 };
00051 
00052 #define DES_IVLEN 8
00053 #define DES_KEYLEN 8
00054 #define DES3_IVLEN 8
00055 #define DES3_KEYLEN 24
00056 
00057 
00058 #ifdef STM32F2_CRYPTO
00059 enum {
00060     DES_CBC = 0,
00061     DES_ECB = 1
00062 };
00063 #endif
00064 
00065 
00066 /* DES encryption and decryption */
00067 typedef struct Des {
00068     word32 reg[DES_BLOCK_SIZE / sizeof(word32)];      /* for CBC mode */
00069     word32 tmp[DES_BLOCK_SIZE / sizeof(word32)];      /* same         */
00070     word32 key[DES_KS_SIZE];
00071 } Des;
00072 
00073 
00074 /* DES3 encryption and decryption */
00075 typedef struct Des3 {
00076     word32 key[3][DES_KS_SIZE];
00077     word32 reg[DES_BLOCK_SIZE / sizeof(word32)];      /* for CBC mode */
00078     word32 tmp[DES_BLOCK_SIZE / sizeof(word32)];      /* same         */
00079 #ifdef HAVE_CAVIUM
00080     int     devId;           /* nitrox device id */
00081     word32  magic;           /* using cavium magic */
00082     word64  contextHandle;   /* nitrox context memory handle */
00083 #endif
00084 } Des3;
00085 #endif /* HAVE_FIPS */
00086 
00087 WOLFSSL_API int  wc_Des_SetKey(Des* des, const byte* key,
00088                                const byte* iv, int dir);
00089 WOLFSSL_API void wc_Des_SetIV(Des* des, const byte* iv);
00090 WOLFSSL_API int  wc_Des_CbcEncrypt(Des* des, byte* out,
00091                                    const byte* in, word32 sz);
00092 WOLFSSL_API int  wc_Des_CbcDecrypt(Des* des, byte* out,
00093                                    const byte* in, word32 sz);
00094 WOLFSSL_API int  wc_Des_EcbEncrypt(Des* des, byte* out,
00095                                    const byte* in, word32 sz);
00096 
00097 WOLFSSL_API int  wc_Des3_SetKey(Des3* des, const byte* key,
00098                                 const byte* iv,int dir);
00099 WOLFSSL_API int  wc_Des3_SetIV(Des3* des, const byte* iv);
00100 WOLFSSL_API int  wc_Des3_CbcEncrypt(Des3* des, byte* out,
00101                                     const byte* in,word32 sz);
00102 WOLFSSL_API int  wc_Des3_CbcDecrypt(Des3* des, byte* out,
00103                                     const byte* in,word32 sz);
00104 
00105 #ifdef HAVE_CAVIUM
00106     WOLFSSL_API int  wc_Des3_InitCavium(Des3*, int);
00107     WOLFSSL_API void wc_Des3_FreeCavium(Des3*);
00108 #endif
00109 
00110 #ifdef __cplusplus
00111     } /* extern "C" */
00112 #endif
00113 
00114 #endif /* NO_DES3 */
00115 #endif /* WOLF_CRYPT_DES3_H */
00116 
00117