fork of cyassl-lib
Dependents: TLS_cyassl TLS_cyassl
cyassl/ctaocrypt/des3.h@0:714293de3836, 2013-09-05 (annotated)
- Committer:
- ashleymills
- Date:
- Thu Sep 05 10:33:04 2013 +0000
- Revision:
- 0:714293de3836
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 0:714293de3836 | 1 | /* des3.h |
ashleymills | 0:714293de3836 | 2 | * |
ashleymills | 0:714293de3836 | 3 | * Copyright (C) 2006-2013 wolfSSL Inc. |
ashleymills | 0:714293de3836 | 4 | * |
ashleymills | 0:714293de3836 | 5 | * This file is part of CyaSSL. |
ashleymills | 0:714293de3836 | 6 | * |
ashleymills | 0:714293de3836 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
ashleymills | 0:714293de3836 | 8 | * it under the terms of the GNU General Public License as published by |
ashleymills | 0:714293de3836 | 9 | * the Free Software Foundation; either version 2 of the License, or |
ashleymills | 0:714293de3836 | 10 | * (at your option) any later version. |
ashleymills | 0:714293de3836 | 11 | * |
ashleymills | 0:714293de3836 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
ashleymills | 0:714293de3836 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ashleymills | 0:714293de3836 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ashleymills | 0:714293de3836 | 15 | * GNU General Public License for more details. |
ashleymills | 0:714293de3836 | 16 | * |
ashleymills | 0:714293de3836 | 17 | * You should have received a copy of the GNU General Public License |
ashleymills | 0:714293de3836 | 18 | * along with this program; if not, write to the Free Software |
ashleymills | 0:714293de3836 | 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
ashleymills | 0:714293de3836 | 20 | */ |
ashleymills | 0:714293de3836 | 21 | |
ashleymills | 0:714293de3836 | 22 | |
ashleymills | 0:714293de3836 | 23 | #ifndef NO_DES3 |
ashleymills | 0:714293de3836 | 24 | |
ashleymills | 0:714293de3836 | 25 | #ifndef CTAO_CRYPT_DES3_H |
ashleymills | 0:714293de3836 | 26 | #define CTAO_CRYPT_DES3_H |
ashleymills | 0:714293de3836 | 27 | |
ashleymills | 0:714293de3836 | 28 | |
ashleymills | 0:714293de3836 | 29 | #include <cyassl/ctaocrypt/types.h> |
ashleymills | 0:714293de3836 | 30 | |
ashleymills | 0:714293de3836 | 31 | |
ashleymills | 0:714293de3836 | 32 | #ifdef __cplusplus |
ashleymills | 0:714293de3836 | 33 | extern "C" { |
ashleymills | 0:714293de3836 | 34 | #endif |
ashleymills | 0:714293de3836 | 35 | |
ashleymills | 0:714293de3836 | 36 | #define CYASSL_3DES_CAVIUM_MAGIC 0xBEEF0003 |
ashleymills | 0:714293de3836 | 37 | |
ashleymills | 0:714293de3836 | 38 | enum { |
ashleymills | 0:714293de3836 | 39 | DES_ENC_TYPE = 2, /* cipher unique type */ |
ashleymills | 0:714293de3836 | 40 | DES3_ENC_TYPE = 3, /* cipher unique type */ |
ashleymills | 0:714293de3836 | 41 | DES_BLOCK_SIZE = 8, |
ashleymills | 0:714293de3836 | 42 | DES_KS_SIZE = 32, |
ashleymills | 0:714293de3836 | 43 | |
ashleymills | 0:714293de3836 | 44 | DES_ENCRYPTION = 0, |
ashleymills | 0:714293de3836 | 45 | DES_DECRYPTION = 1 |
ashleymills | 0:714293de3836 | 46 | }; |
ashleymills | 0:714293de3836 | 47 | |
ashleymills | 0:714293de3836 | 48 | #ifdef STM32F2_CRYPTO |
ashleymills | 0:714293de3836 | 49 | enum { |
ashleymills | 0:714293de3836 | 50 | DES_CBC = 0, |
ashleymills | 0:714293de3836 | 51 | DES_ECB = 1 |
ashleymills | 0:714293de3836 | 52 | }; |
ashleymills | 0:714293de3836 | 53 | #endif |
ashleymills | 0:714293de3836 | 54 | |
ashleymills | 0:714293de3836 | 55 | |
ashleymills | 0:714293de3836 | 56 | /* DES encryption and decryption */ |
ashleymills | 0:714293de3836 | 57 | typedef struct Des { |
ashleymills | 0:714293de3836 | 58 | word32 key[DES_KS_SIZE]; |
ashleymills | 0:714293de3836 | 59 | word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ |
ashleymills | 0:714293de3836 | 60 | word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */ |
ashleymills | 0:714293de3836 | 61 | } Des; |
ashleymills | 0:714293de3836 | 62 | |
ashleymills | 0:714293de3836 | 63 | |
ashleymills | 0:714293de3836 | 64 | /* DES3 encryption and decryption */ |
ashleymills | 0:714293de3836 | 65 | typedef struct Des3 { |
ashleymills | 0:714293de3836 | 66 | word32 key[3][DES_KS_SIZE]; |
ashleymills | 0:714293de3836 | 67 | word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ |
ashleymills | 0:714293de3836 | 68 | word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */ |
ashleymills | 0:714293de3836 | 69 | #ifdef HAVE_CAVIUM |
ashleymills | 0:714293de3836 | 70 | int devId; /* nitrox device id */ |
ashleymills | 0:714293de3836 | 71 | word32 magic; /* using cavium magic */ |
ashleymills | 0:714293de3836 | 72 | word64 contextHandle; /* nitrox context memory handle */ |
ashleymills | 0:714293de3836 | 73 | #endif |
ashleymills | 0:714293de3836 | 74 | } Des3; |
ashleymills | 0:714293de3836 | 75 | |
ashleymills | 0:714293de3836 | 76 | |
ashleymills | 0:714293de3836 | 77 | CYASSL_API void Des_SetKey(Des* des, const byte* key, const byte* iv, int dir); |
ashleymills | 0:714293de3836 | 78 | CYASSL_API void Des_SetIV(Des* des, const byte* iv); |
ashleymills | 0:714293de3836 | 79 | CYASSL_API void Des_CbcEncrypt(Des* des, byte* out, const byte* in, word32 sz); |
ashleymills | 0:714293de3836 | 80 | CYASSL_API void Des_CbcDecrypt(Des* des, byte* out, const byte* in, word32 sz); |
ashleymills | 0:714293de3836 | 81 | CYASSL_API void Des_EcbEncrypt(Des* des, byte* out, const byte* in, word32 sz); |
ashleymills | 0:714293de3836 | 82 | |
ashleymills | 0:714293de3836 | 83 | CYASSL_API void Des3_SetKey(Des3* des, const byte* key, const byte* iv,int dir); |
ashleymills | 0:714293de3836 | 84 | CYASSL_API void Des3_SetIV(Des3* des, const byte* iv); |
ashleymills | 0:714293de3836 | 85 | CYASSL_API void Des3_CbcEncrypt(Des3* des, byte* out, const byte* in,word32 sz); |
ashleymills | 0:714293de3836 | 86 | CYASSL_API void Des3_CbcDecrypt(Des3* des, byte* out, const byte* in,word32 sz); |
ashleymills | 0:714293de3836 | 87 | |
ashleymills | 0:714293de3836 | 88 | |
ashleymills | 0:714293de3836 | 89 | #ifdef HAVE_CAVIUM |
ashleymills | 0:714293de3836 | 90 | CYASSL_API int Des3_InitCavium(Des3*, int); |
ashleymills | 0:714293de3836 | 91 | CYASSL_API void Des3_FreeCavium(Des3*); |
ashleymills | 0:714293de3836 | 92 | #endif |
ashleymills | 0:714293de3836 | 93 | |
ashleymills | 0:714293de3836 | 94 | |
ashleymills | 0:714293de3836 | 95 | #ifdef __cplusplus |
ashleymills | 0:714293de3836 | 96 | } /* extern "C" */ |
ashleymills | 0:714293de3836 | 97 | #endif |
ashleymills | 0:714293de3836 | 98 | |
ashleymills | 0:714293de3836 | 99 | #endif /* NO_DES3 */ |
ashleymills | 0:714293de3836 | 100 | #endif /* CTAO_CRYPT_DES3_H */ |
ashleymills | 0:714293de3836 | 101 |