Renesas / SecureDweet
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers des.h Source File

des.h

00001 /* des.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 
00024 /*  des.h defines mini des openssl compatibility layer 
00025  *
00026  */
00027 
00028 
00029 #ifndef WOLFSSL_DES_H_
00030 #define WOLFSSL_DES_H_
00031 
00032 #include <wolfssl/wolfcrypt/settings.h>
00033 
00034 #ifndef NO_DES3
00035 
00036 #ifdef WOLFSSL_PREFIX
00037 #include "prefix_des.h"
00038 #endif
00039 
00040 
00041 #ifdef __cplusplus
00042     extern "C" {
00043 #endif
00044 
00045 typedef unsigned char WOLFSSL_DES_cblock[8];
00046 typedef /* const */ WOLFSSL_DES_cblock WOLFSSL_const_DES_cblock;
00047 typedef WOLFSSL_DES_cblock WOLFSSL_DES_key_schedule;
00048 
00049 
00050 enum {
00051     DES_ENCRYPT = 1,
00052     DES_DECRYPT = 0
00053 };
00054 
00055 
00056 WOLFSSL_API void wolfSSL_DES_set_key_unchecked(WOLFSSL_const_DES_cblock*,
00057                                              WOLFSSL_DES_key_schedule*);
00058 WOLFSSL_API int  wolfSSL_DES_key_sched(WOLFSSL_const_DES_cblock* key,
00059                                      WOLFSSL_DES_key_schedule* schedule);
00060 WOLFSSL_API void wolfSSL_DES_cbc_encrypt(const unsigned char* input,
00061                      unsigned char* output, long length,
00062                      WOLFSSL_DES_key_schedule* schedule, WOLFSSL_DES_cblock* ivec,
00063                      int enc);
00064 WOLFSSL_API void wolfSSL_DES_ncbc_encrypt(const unsigned char* input,
00065                       unsigned char* output, long length,
00066                       WOLFSSL_DES_key_schedule* schedule,
00067                       WOLFSSL_DES_cblock* ivec, int enc);
00068 
00069 WOLFSSL_API void wolfSSL_DES_set_odd_parity(WOLFSSL_DES_cblock*);
00070 WOLFSSL_API void wolfSSL_DES_ecb_encrypt(WOLFSSL_DES_cblock*, WOLFSSL_DES_cblock*,
00071                                        WOLFSSL_DES_key_schedule*, int);
00072 
00073 
00074 typedef WOLFSSL_DES_cblock DES_cblock;
00075 typedef WOLFSSL_const_DES_cblock const_DES_cblock;
00076 typedef WOLFSSL_DES_key_schedule DES_key_schedule;
00077 
00078 #define DES_set_key_unchecked wolfSSL_DES_set_key_unchecked
00079 #define DES_key_sched wolfSSL_DES_key_sched
00080 #define DES_cbc_encrypt wolfSSL_DES_cbc_encrypt
00081 #define DES_ncbc_encrypt wolfSSL_DES_ncbc_encrypt
00082 #define DES_set_odd_parity wolfSSL_DES_set_odd_parity
00083 #define DES_ecb_encrypt wolfSSL_DES_ecb_encrypt
00084 #define DES_ede3_cbc_encrypt(input, output, sz, ks1, ks2, ks3, ivec, enc) \
00085 do {                                                         \
00086     Des3 des;                                                \
00087     byte key[24];/* EDE uses 24 size key */                  \
00088     memcpy(key, (ks1), DES_BLOCK_SIZE);                      \
00089     memcpy(&key[DES_BLOCK_SIZE], (ks2), DES_BLOCK_SIZE);     \
00090     memcpy(&key[DES_BLOCK_SIZE * 2], (ks3), DES_BLOCK_SIZE); \
00091     if (enc) {                                               \
00092         wc_Des3_SetKey(&des, key, (const byte*)(ivec), DES_ENCRYPTION);    \
00093         wc_Des3_CbcEncrypt(&des, (output), (input), (sz));    \
00094     }                                                         \
00095     else {                                                    \
00096         wc_Des3_SetKey(&des, key, (const byte*)(ivec), DES_ENCRYPTION);    \
00097         wc_Des3_CbcDecrypt(&des, (output), (input), (sz));    \
00098     }                                                         \
00099 } while(0)
00100 
00101 #ifdef __cplusplus
00102     } /* extern "C" */
00103 #endif
00104 
00105 #endif /* NO_DES3 */
00106 
00107 #endif /* WOLFSSL_DES_H_ */
00108