diff options
Diffstat (limited to 'FreeRTOS-Plus/Source/WolfSSL/wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h')
-rw-r--r-- | FreeRTOS-Plus/Source/WolfSSL/wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h | 188 |
1 files changed, 137 insertions, 51 deletions
diff --git a/FreeRTOS-Plus/Source/WolfSSL/wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h b/FreeRTOS-Plus/Source/WolfSSL/wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h index 44c54d74e..bb288c777 100644 --- a/FreeRTOS-Plus/Source/WolfSSL/wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h +++ b/FreeRTOS-Plus/Source/WolfSSL/wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h @@ -1,8 +1,8 @@ /* pic32mz-crypt.h * - * Copyright (C) 2006-2015 wolfSSL Inc. + * Copyright (C) 2006-2020 wolfSSL Inc. * - * This file is part of wolfSSL. (formerly known as CyaSSL) + * This file is part of wolfSSL. * * wolfSSL is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,19 +16,48 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ + #ifndef PIC32MZ_CRYPT_H #define PIC32MZ_CRYPT_H -#ifdef WOLFSSL_MICROCHIP_PIC32MZ +#ifdef __cplusplus + extern "C" { +#endif + +#include <wolfssl/wolfcrypt/settings.h> + +#ifdef WOLFSSL_MICROCHIP_PIC32MZ + +#ifndef MICROCHIP_PIC32 + #define MICROCHIP_PIC32 +#endif + +/* If algos aren't enabled then turn off */ +#ifdef WOLFSSL_PIC32MZ_HASH + #if defined(NO_MD5) && defined(NO_SHA) && defined(NO_SHA256) + #undef WOLFSSL_PIC32MZ_HASH + #endif +#endif + +#ifdef WOLFSSL_PIC32MZ_CRYPT + #if defined(NO_AES) && defined(NO_DES3) + #undef WOLFSSL_PIC32MZ_CRYPT + #endif +#endif + +/* Enables support for large hashing */ +/* requires exclusive access to crypto hardware done at application layer */ +#define WOLFSSL_PIC32MZ_LARGE_HASH -#define MICROCHIP_PIC32 #include <xc.h> #include <sys/endian.h> #include <sys/kmem.h> + +/* PIC32 Crypto Structures */ typedef struct saCtrl { unsigned int CRYPTOALGO : 4; unsigned int MULTITASK : 3; @@ -62,11 +91,12 @@ typedef struct bdCtrl { unsigned int CBD_INT_EN : 1; unsigned int PKT_INT_EN : 1; unsigned int LIFM : 1; - unsigned int LAST_BD: 1; - unsigned int : 2; + unsigned int LAST_BD : 1; + unsigned int CRDMA_EN : 1; + unsigned int UPD_RES : 1; unsigned int SA_FETCH_EN : 1; - unsigned int : 8; - unsigned int DESC_EN : 1; + unsigned int SEC_CODE : 8; + volatile unsigned int DESC_EN : 1; } bdCtrl; typedef struct bufferDescriptor { @@ -81,58 +111,114 @@ typedef struct bufferDescriptor { } bufferDescriptor; -#define PIC32_ENCRYPTION 0b1 -#define PIC32_DECRYPTION 0b0 +/* Cache Updates Struct */ +typedef struct hashUpdCache { + unsigned char* buf; + unsigned int bufLen; + unsigned int updLen; + int isCopy; +#ifdef WOLFSSL_PIC32MZ_LARGE_HASH + unsigned int finalLen; +#endif +} hashUpdCache; + +/* Direction */ +#define PIC32_ENCRYPTION 0b1 +#define PIC32_DECRYPTION 0b0 + +/* Algorithm */ #define PIC32_ALGO_HMAC1 0b01000000 #define PIC32_ALGO_SHA256 0b00100000 #define PIC32_ALGO_SHA1 0b00010000 #define PIC32_ALGO_MD5 0b00001000 + #define PIC32_ALGO_AES 0b00000100 #define PIC32_ALGO_TDES 0b00000010 #define PIC32_ALGO_DES 0b00000001 -#define PIC32_CRYPTOALGO_AES_GCM 0b1110 -#define PIC32_CRYPTOALGO_RCTR 0b1101 -#define PIC32_CRYPTOALGO_RCBC 0b1001 -#define PIC32_CRYPTOALGO_REBC 0b1000 -#define PIC32_CRYPTOALGO_TCBC 0b0101 -#define PIC32_CRYPTOALGO_CBC 0b0001 - -#define PIC32_AES_KEYSIZE_256 0b10 -#define PIC32_AES_KEYSIZE_192 0b01 -#define PIC32_AES_KEYSIZE_128 0b00 - -#define PIC32_AES_BLOCK_SIZE 16 -#define MD5_HASH_SIZE 16 -#define SHA1_HASH_SIZE 20 -#define SHA256_HASH_SIZE 32 -#define PIC32_HASH_SIZE 32 - -#define PIC32MZ_MAX_BD 2 -typedef struct { /* Crypt Engine descripter */ - int bdCount ; - int err ; - volatile bufferDescriptor - bd[PIC32MZ_MAX_BD] __attribute__((aligned (8), coherent)); - securityAssociation - sa __attribute__((aligned (8), coherent)); -} pic32mz_desc ; - -#define PIC32MZ_IF_RAM(addr) (KVA_TO_PA(addr) < 0x80000) - -#define WAIT_ENGINE \ - { volatile int v ; while (CESTATbits.ACTIVE) ; for(v=0; v<100; v++) ; } - -#ifdef DEBUG_CYASSL -static void print_mem(const unsigned char *p, int size) { - for(; size>0; size--, p++) { - if(size%4 == 0)printf(" ") ; - printf("%02x", (int)*p) ; - } - puts("") ; -} +/* Crypto Algo */ +/* AES */ +#define PIC32_CRYPTOALGO_AES_GCM 0b1110 +#define PIC32_CRYPTOALGO_RCTR 0b1101 +#define PIC32_CRYPTOALGO_RCBC_MAC 0b1100 +#define PIC32_CRYPTOALGO_ROFB 0b1011 +#define PIC32_CRYPTOALGO_RCFB 0b1010 +#define PIC32_CRYPTOALGO_RCBC 0b1001 +#define PIC32_CRYPTOALGO_RECB 0b1000 +/* Triple-DES */ +#define PIC32_CRYPTOALGO_TOFB 0b0111 +#define PIC32_CRYPTOALGO_TCFB 0b0110 +#define PIC32_CRYPTOALGO_TCBC 0b0101 +#define PIC32_CRYPTOALGO_TECB 0b0100 +/* DES */ +#define PIC32_CRYPTOALGO_OFB 0b0011 +#define PIC32_CRYPTOALGO_CFB 0b0010 +#define PIC32_CRYPTOALGO_CBC 0b0001 +#define PIC32_CRYPTOALGO_ECB 0b0000 + +/* Key Size */ +#define PIC32_KEYSIZE_256 0b10 +#define PIC32_KEYSIZE_192 0b01 +#define PIC32_KEYSIZE_128 0b00 + +/* PIC32 Minimum Buffer/Block Sizes */ +#define PIC32_BLOCKSIZE_HASH 64 +#define PIC32_BLOCKSIZE_HMAC PIC32_BLOCKSIZE_HASH +#define PIC32_BLOCKSIZE_MD5 PIC32_BLOCKSIZE_HASH +#define PIC32_BLOCKSIZE_SHA1 PIC32_BLOCKSIZE_HASH +#define PIC32_BLOCKSIZE_SHA256 PIC32_BLOCKSIZE_HASH +#define PIC32_BLOCKSIZE_AES 16 +#define PIC32_BLOCKSIZE_TDES 24 +#define PIC32_BLOCKSIZE_DES 8 + +#define PIC32_DIGEST_SIZE 32 + + +/* Helper Macros */ +#define PIC32MZ_IF_RAM(addr) (KVA_TO_PA(addr) < 0x1D000000) + +/* If EF part then Crypto engine supports swapping output bytes */ +#define PIC32_NO_OUT_SWAP ((__PIC32_FEATURE_SET0 == 'E') && \ + (__PIC32_FEATURE_SET1 == 'C')) + + +#ifndef NO_AES +int wc_Pic32AesCrypt(word32 *key, int keyLen, word32 *iv, int ivLen, + byte* out, const byte* in, word32 sz, + int dir, int algo, int cryptoalgo); +#endif +#ifndef NO_DES3 +int wc_Pic32DesCrypt(word32 *key, int keyLen, word32 *iv, int ivLen, + byte* out, const byte* in, word32 sz, + int dir, int algo, int cryptoalgo); #endif +#ifdef WOLFSSL_PIC32MZ_HASH +#define WOLFSSL_NO_HASH_RAW + +int wc_Pic32Hash(const byte* in, int inLen, word32* out, int outLen, int algo); +int wc_Pic32HashCopy(hashUpdCache* src, hashUpdCache* dst); + +#ifndef NO_MD5 +struct wc_Md5; +void wc_Md5Pic32Free(struct wc_Md5* md5); +#endif +#ifndef NO_SHA +struct wc_Sha; +void wc_ShaPic32Free(struct wc_Sha* sha); #endif + +#ifndef NO_SHA256 +struct wc_Sha256; +void wc_Sha256Pic32Free(struct wc_Sha256* sha256); +#endif +#endif /* WOLFSSL_PIC32MZ_HASH */ + +#endif /* WOLFSSL_MICROCHIP_PIC32MZ */ + +#ifdef __cplusplus + } /* extern "C" */ +#endif + #endif /* PIC32MZ_CRYPT_H */ |