cyassl re-port with cellular comms, PSK test

Dependencies:   VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src

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-2012 Sawtooth Consulting Ltd.
00004  *
00005  * This file is part of CyaSSL.
00006  *
00007  * CyaSSL 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  * CyaSSL 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00020  */
00021 
00022 
00023 #ifndef NO_DES3
00024 
00025 #ifndef CTAO_CRYPT_DES3_H
00026 #define CTAO_CRYPT_DES3_H
00027 
00028 
00029 #include <cyassl/ctaocrypt/types.h>
00030 
00031 
00032 #ifdef __cplusplus
00033     extern "C" {
00034 #endif
00035 
00036 #define CYASSL_3DES_CAVIUM_MAGIC 0xBEEF0003
00037 
00038 enum {
00039     DES_ENC_TYPE    = 2,     /* cipher unique type */
00040     DES3_ENC_TYPE   = 3,     /* cipher unique type */
00041     DES_BLOCK_SIZE  = 8,
00042     DES_KS_SIZE     = 32,
00043 
00044     DES_ENCRYPTION  = 0,
00045     DES_DECRYPTION  = 1
00046 };
00047 
00048 #ifdef STM32F2_CRYPTO
00049 enum {
00050     DES_CBC = 0,
00051     DES_ECB = 1
00052 };
00053 #endif
00054 
00055 
00056 /* DES encryption and decryption */
00057 typedef struct Des {
00058     word32 key[DES_KS_SIZE];
00059     word32 reg[DES_BLOCK_SIZE / sizeof(word32)];      /* for CBC mode */
00060     word32 tmp[DES_BLOCK_SIZE / sizeof(word32)];      /* same         */
00061 } Des;
00062 
00063 
00064 /* DES3 encryption and decryption */
00065 typedef struct Des3 {
00066     word32 key[3][DES_KS_SIZE];
00067     word32 reg[DES_BLOCK_SIZE / sizeof(word32)];      /* for CBC mode */
00068     word32 tmp[DES_BLOCK_SIZE / sizeof(word32)];      /* same         */
00069 #ifdef HAVE_CAVIUM
00070     int     devId;           /* nitrox device id */
00071     word32  magic;           /* using cavium magic */
00072     word64  contextHandle;   /* nitrox context memory handle */
00073 #endif
00074 } Des3;
00075 
00076 
00077 CYASSL_API void Des_SetKey(Des* des, const byte* key, const byte* iv, int dir);
00078 CYASSL_API void Des_SetIV(Des* des, const byte* iv);
00079 CYASSL_API void Des_CbcEncrypt(Des* des, byte* out, const byte* in, word32 sz);
00080 CYASSL_API void Des_CbcDecrypt(Des* des, byte* out, const byte* in, word32 sz);
00081 CYASSL_API void Des_EcbEncrypt(Des* des, byte* out, const byte* in, word32 sz);
00082 
00083 CYASSL_API void Des3_SetKey(Des3* des, const byte* key, const byte* iv,int dir);
00084 CYASSL_API void Des3_SetIV(Des3* des, const byte* iv);
00085 CYASSL_API void Des3_CbcEncrypt(Des3* des, byte* out, const byte* in,word32 sz);
00086 CYASSL_API void Des3_CbcDecrypt(Des3* des, byte* out, const byte* in,word32 sz);
00087 
00088 
00089 #ifdef HAVE_CAVIUM
00090     CYASSL_API int  Des3_InitCavium(Des3*, int);
00091     CYASSL_API void Des3_FreeCavium(Des3*);
00092 #endif
00093 
00094 
00095 #ifdef __cplusplus
00096     } /* extern "C" */
00097 #endif
00098 
00099 #endif /* NO_DES3 */
00100 #endif /* CTAO_CRYPT_DES3_H */
00101