Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of wolfSSL by
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 00041 #ifdef WOLFSSL_ASYNC_CRYPT 00042 #include <wolfssl/wolfcrypt/async.h> 00043 #endif 00044 00045 enum { 00046 DES_ENC_TYPE = 2, /* cipher unique type */ 00047 DES3_ENC_TYPE = 3, /* cipher unique type */ 00048 DES_BLOCK_SIZE = 8, 00049 DES_KS_SIZE = 32, 00050 00051 DES_ENCRYPTION = 0, 00052 DES_DECRYPTION = 1 00053 }; 00054 00055 #define DES_IVLEN 8 00056 #define DES_KEYLEN 8 00057 #define DES3_IVLEN 8 00058 #define DES3_KEYLEN 24 00059 00060 00061 #if defined(STM32F2_CRYPTO) || defined(STM32F4_CRYPTO) 00062 enum { 00063 DES_CBC = 0, 00064 DES_ECB = 1 00065 }; 00066 #endif 00067 00068 00069 /* DES encryption and decryption */ 00070 typedef struct Des { 00071 word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ 00072 word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */ 00073 word32 key[DES_KS_SIZE]; 00074 } Des; 00075 00076 00077 /* DES3 encryption and decryption */ 00078 typedef struct Des3 { 00079 word32 key[3][DES_KS_SIZE]; 00080 word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ 00081 word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */ 00082 #ifdef WOLFSSL_ASYNC_CRYPT 00083 const byte* key_raw; 00084 const byte* iv_raw; 00085 WC_ASYNC_DEV asyncDev; 00086 #endif 00087 void* heap; 00088 } Des3; 00089 #endif /* HAVE_FIPS */ 00090 00091 00092 WOLFSSL_API int wc_Des_SetKey(Des* des, const byte* key, 00093 const byte* iv, int dir); 00094 WOLFSSL_API void wc_Des_SetIV(Des* des, const byte* iv); 00095 WOLFSSL_API int wc_Des_CbcEncrypt(Des* des, byte* out, 00096 const byte* in, word32 sz); 00097 WOLFSSL_API int wc_Des_CbcDecrypt(Des* des, byte* out, 00098 const byte* in, word32 sz); 00099 WOLFSSL_API int wc_Des_EcbEncrypt(Des* des, byte* out, 00100 const byte* in, word32 sz); 00101 WOLFSSL_API int wc_Des3_EcbEncrypt(Des3* des, byte* out, 00102 const byte* in, word32 sz); 00103 00104 /* ECB decrypt same process as encrypt but with decrypt key */ 00105 #define wc_Des_EcbDecrypt wc_Des_EcbEncrypt 00106 #define wc_Des3_EcbDecrypt wc_Des3_EcbEncrypt 00107 00108 WOLFSSL_API int wc_Des3_SetKey(Des3* des, const byte* key, 00109 const byte* iv,int dir); 00110 WOLFSSL_API int wc_Des3_SetIV(Des3* des, const byte* iv); 00111 WOLFSSL_API int wc_Des3_CbcEncrypt(Des3* des, byte* out, 00112 const byte* in,word32 sz); 00113 WOLFSSL_API int wc_Des3_CbcDecrypt(Des3* des, byte* out, 00114 const byte* in,word32 sz); 00115 00116 /* These are only required when using either: 00117 static memory (WOLFSSL_STATIC_MEMORY) or asynchronous (WOLFSSL_ASYNC_CRYPT) */ 00118 WOLFSSL_API int wc_Des3Init(Des3*, void*, int); 00119 WOLFSSL_API void wc_Des3Free(Des3*); 00120 00121 #ifdef __cplusplus 00122 } /* extern "C" */ 00123 #endif 00124 00125 #endif /* NO_DES3 */ 00126 #endif /* WOLF_CRYPT_DES3_H */ 00127 00128
Generated on Tue Jul 12 2022 23:30:55 by
1.7.2
