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.
wolfssl/wolfcrypt/des3.h@4:1b0d80432c79, 2016-04-28 (annotated)
- Committer:
- wolfSSL
- Date:
- Thu Apr 28 00:57:21 2016 +0000
- Revision:
- 4:1b0d80432c79
wolfSSL 3.9.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 4:1b0d80432c79 | 1 | /* des3.h |
wolfSSL | 4:1b0d80432c79 | 2 | * |
wolfSSL | 4:1b0d80432c79 | 3 | * Copyright (C) 2006-2016 wolfSSL Inc. |
wolfSSL | 4:1b0d80432c79 | 4 | * |
wolfSSL | 4:1b0d80432c79 | 5 | * This file is part of wolfSSL. |
wolfSSL | 4:1b0d80432c79 | 6 | * |
wolfSSL | 4:1b0d80432c79 | 7 | * wolfSSL is free software; you can redistribute it and/or modify |
wolfSSL | 4:1b0d80432c79 | 8 | * it under the terms of the GNU General Public License as published by |
wolfSSL | 4:1b0d80432c79 | 9 | * the Free Software Foundation; either version 2 of the License, or |
wolfSSL | 4:1b0d80432c79 | 10 | * (at your option) any later version. |
wolfSSL | 4:1b0d80432c79 | 11 | * |
wolfSSL | 4:1b0d80432c79 | 12 | * wolfSSL is distributed in the hope that it will be useful, |
wolfSSL | 4:1b0d80432c79 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wolfSSL | 4:1b0d80432c79 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wolfSSL | 4:1b0d80432c79 | 15 | * GNU General Public License for more details. |
wolfSSL | 4:1b0d80432c79 | 16 | * |
wolfSSL | 4:1b0d80432c79 | 17 | * You should have received a copy of the GNU General Public License |
wolfSSL | 4:1b0d80432c79 | 18 | * along with this program; if not, write to the Free Software |
wolfSSL | 4:1b0d80432c79 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
wolfSSL | 4:1b0d80432c79 | 20 | */ |
wolfSSL | 4:1b0d80432c79 | 21 | |
wolfSSL | 4:1b0d80432c79 | 22 | |
wolfSSL | 4:1b0d80432c79 | 23 | #ifndef WOLF_CRYPT_DES3_H |
wolfSSL | 4:1b0d80432c79 | 24 | #define WOLF_CRYPT_DES3_H |
wolfSSL | 4:1b0d80432c79 | 25 | |
wolfSSL | 4:1b0d80432c79 | 26 | #include <wolfssl/wolfcrypt/types.h> |
wolfSSL | 4:1b0d80432c79 | 27 | |
wolfSSL | 4:1b0d80432c79 | 28 | #ifndef NO_DES3 |
wolfSSL | 4:1b0d80432c79 | 29 | |
wolfSSL | 4:1b0d80432c79 | 30 | #ifdef HAVE_FIPS |
wolfSSL | 4:1b0d80432c79 | 31 | /* included for fips @wc_fips */ |
wolfSSL | 4:1b0d80432c79 | 32 | #include <cyassl/ctaocrypt/des3.h> |
wolfSSL | 4:1b0d80432c79 | 33 | #endif |
wolfSSL | 4:1b0d80432c79 | 34 | |
wolfSSL | 4:1b0d80432c79 | 35 | #ifdef __cplusplus |
wolfSSL | 4:1b0d80432c79 | 36 | extern "C" { |
wolfSSL | 4:1b0d80432c79 | 37 | #endif |
wolfSSL | 4:1b0d80432c79 | 38 | |
wolfSSL | 4:1b0d80432c79 | 39 | #ifndef HAVE_FIPS /* to avoid redefinition of macros */ |
wolfSSL | 4:1b0d80432c79 | 40 | #define WOLFSSL_3DES_CAVIUM_MAGIC 0xBEEF0003 |
wolfSSL | 4:1b0d80432c79 | 41 | |
wolfSSL | 4:1b0d80432c79 | 42 | enum { |
wolfSSL | 4:1b0d80432c79 | 43 | DES_ENC_TYPE = 2, /* cipher unique type */ |
wolfSSL | 4:1b0d80432c79 | 44 | DES3_ENC_TYPE = 3, /* cipher unique type */ |
wolfSSL | 4:1b0d80432c79 | 45 | DES_BLOCK_SIZE = 8, |
wolfSSL | 4:1b0d80432c79 | 46 | DES_KS_SIZE = 32, |
wolfSSL | 4:1b0d80432c79 | 47 | |
wolfSSL | 4:1b0d80432c79 | 48 | DES_ENCRYPTION = 0, |
wolfSSL | 4:1b0d80432c79 | 49 | DES_DECRYPTION = 1 |
wolfSSL | 4:1b0d80432c79 | 50 | }; |
wolfSSL | 4:1b0d80432c79 | 51 | |
wolfSSL | 4:1b0d80432c79 | 52 | #define DES_IVLEN 8 |
wolfSSL | 4:1b0d80432c79 | 53 | #define DES_KEYLEN 8 |
wolfSSL | 4:1b0d80432c79 | 54 | #define DES3_IVLEN 8 |
wolfSSL | 4:1b0d80432c79 | 55 | #define DES3_KEYLEN 24 |
wolfSSL | 4:1b0d80432c79 | 56 | |
wolfSSL | 4:1b0d80432c79 | 57 | |
wolfSSL | 4:1b0d80432c79 | 58 | #ifdef STM32F2_CRYPTO |
wolfSSL | 4:1b0d80432c79 | 59 | enum { |
wolfSSL | 4:1b0d80432c79 | 60 | DES_CBC = 0, |
wolfSSL | 4:1b0d80432c79 | 61 | DES_ECB = 1 |
wolfSSL | 4:1b0d80432c79 | 62 | }; |
wolfSSL | 4:1b0d80432c79 | 63 | #endif |
wolfSSL | 4:1b0d80432c79 | 64 | |
wolfSSL | 4:1b0d80432c79 | 65 | |
wolfSSL | 4:1b0d80432c79 | 66 | /* DES encryption and decryption */ |
wolfSSL | 4:1b0d80432c79 | 67 | typedef struct Des { |
wolfSSL | 4:1b0d80432c79 | 68 | word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ |
wolfSSL | 4:1b0d80432c79 | 69 | word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */ |
wolfSSL | 4:1b0d80432c79 | 70 | word32 key[DES_KS_SIZE]; |
wolfSSL | 4:1b0d80432c79 | 71 | } Des; |
wolfSSL | 4:1b0d80432c79 | 72 | |
wolfSSL | 4:1b0d80432c79 | 73 | |
wolfSSL | 4:1b0d80432c79 | 74 | /* DES3 encryption and decryption */ |
wolfSSL | 4:1b0d80432c79 | 75 | typedef struct Des3 { |
wolfSSL | 4:1b0d80432c79 | 76 | word32 key[3][DES_KS_SIZE]; |
wolfSSL | 4:1b0d80432c79 | 77 | word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ |
wolfSSL | 4:1b0d80432c79 | 78 | word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */ |
wolfSSL | 4:1b0d80432c79 | 79 | #ifdef HAVE_CAVIUM |
wolfSSL | 4:1b0d80432c79 | 80 | int devId; /* nitrox device id */ |
wolfSSL | 4:1b0d80432c79 | 81 | word32 magic; /* using cavium magic */ |
wolfSSL | 4:1b0d80432c79 | 82 | word64 contextHandle; /* nitrox context memory handle */ |
wolfSSL | 4:1b0d80432c79 | 83 | #endif |
wolfSSL | 4:1b0d80432c79 | 84 | } Des3; |
wolfSSL | 4:1b0d80432c79 | 85 | #endif /* HAVE_FIPS */ |
wolfSSL | 4:1b0d80432c79 | 86 | |
wolfSSL | 4:1b0d80432c79 | 87 | WOLFSSL_API int wc_Des_SetKey(Des* des, const byte* key, |
wolfSSL | 4:1b0d80432c79 | 88 | const byte* iv, int dir); |
wolfSSL | 4:1b0d80432c79 | 89 | WOLFSSL_API void wc_Des_SetIV(Des* des, const byte* iv); |
wolfSSL | 4:1b0d80432c79 | 90 | WOLFSSL_API int wc_Des_CbcEncrypt(Des* des, byte* out, |
wolfSSL | 4:1b0d80432c79 | 91 | const byte* in, word32 sz); |
wolfSSL | 4:1b0d80432c79 | 92 | WOLFSSL_API int wc_Des_CbcDecrypt(Des* des, byte* out, |
wolfSSL | 4:1b0d80432c79 | 93 | const byte* in, word32 sz); |
wolfSSL | 4:1b0d80432c79 | 94 | WOLFSSL_API int wc_Des_EcbEncrypt(Des* des, byte* out, |
wolfSSL | 4:1b0d80432c79 | 95 | const byte* in, word32 sz); |
wolfSSL | 4:1b0d80432c79 | 96 | |
wolfSSL | 4:1b0d80432c79 | 97 | WOLFSSL_API int wc_Des3_SetKey(Des3* des, const byte* key, |
wolfSSL | 4:1b0d80432c79 | 98 | const byte* iv,int dir); |
wolfSSL | 4:1b0d80432c79 | 99 | WOLFSSL_API int wc_Des3_SetIV(Des3* des, const byte* iv); |
wolfSSL | 4:1b0d80432c79 | 100 | WOLFSSL_API int wc_Des3_CbcEncrypt(Des3* des, byte* out, |
wolfSSL | 4:1b0d80432c79 | 101 | const byte* in,word32 sz); |
wolfSSL | 4:1b0d80432c79 | 102 | WOLFSSL_API int wc_Des3_CbcDecrypt(Des3* des, byte* out, |
wolfSSL | 4:1b0d80432c79 | 103 | const byte* in,word32 sz); |
wolfSSL | 4:1b0d80432c79 | 104 | |
wolfSSL | 4:1b0d80432c79 | 105 | #ifdef HAVE_CAVIUM |
wolfSSL | 4:1b0d80432c79 | 106 | WOLFSSL_API int wc_Des3_InitCavium(Des3*, int); |
wolfSSL | 4:1b0d80432c79 | 107 | WOLFSSL_API void wc_Des3_FreeCavium(Des3*); |
wolfSSL | 4:1b0d80432c79 | 108 | #endif |
wolfSSL | 4:1b0d80432c79 | 109 | |
wolfSSL | 4:1b0d80432c79 | 110 | #ifdef __cplusplus |
wolfSSL | 4:1b0d80432c79 | 111 | } /* extern "C" */ |
wolfSSL | 4:1b0d80432c79 | 112 | #endif |
wolfSSL | 4:1b0d80432c79 | 113 | |
wolfSSL | 4:1b0d80432c79 | 114 | #endif /* NO_DES3 */ |
wolfSSL | 4:1b0d80432c79 | 115 | #endif /* WOLF_CRYPT_DES3_H */ |
wolfSSL | 4:1b0d80432c79 | 116 | |
wolfSSL | 4:1b0d80432c79 | 117 |