Code Monkey home page Code Monkey logo

crypto's Introduction

MPLAB® Harmony Crypto Library

The Cryptographic Library includes functions to perform encryption, decryption, hashing, authentication, and compression within the embedded application. Random number generation (RNG) functions are also provided.

Block Ciphers

The library provides DES, 3DES, and AES for block cipher needs. Depending on the algorithm in use, CBC and CTR modes are supported.

Public Key Cryptography

The library provides RSA and Elliptic Curve Cryptography (ECC) for Public Key Cryptography, and Diffie-Hellman (DH) for key agreement arrangements.

Hash Functions

The library provides MD5, SHA, SHA-256, SHA-384, and SHA-512 for hashing. These functions do not require keys or initialization vectors (IV).

Random Number Generation Functions

The library provides functions to generate either a single pseudo-random number, or a block of such numbers

Library Interface

The Library Interface routines are divided into various sub-sections, which address one of the blocks or the overall operation of the Cryptographic (Crypto) Library module.

Library Interface Section Description
General Functions Provides an error string function, which takes an error and converts it into human-readable text.
Compression Functions Provides Huffman compression and decompression functions.
MD5 Functions Provides data add, finalize, and initialize MD5 functions.
Random Number Generator Functions Provides get, initialize, and block generate RNG functions.
AES Encryption/Decryption Functions Provides AES encryption and decryption functions.
ECC Encryption/Decryption Functions Provides ECC encryption and decryption functions.
RSA Encryption/Decryption Functions Provides RSA encryption and decryption functions.
Triple DES Encryption/Decryption Functions Provides 3DES encryption and decryption functions.
HMAC Hash Functions Provides HMAC data add, finalize, and set key Hash functions.
SHA Hash Functions Provides SHA data add, finalize, and initialize Hash functions.
SHA256 Hash Functions Provides SHA256 data add, finalize, and initialize Hash functions.
SHA384 Hash Functions Provides SHA384 data add, finalize, and initialize Hash functions.
SHA512 Hash Functions Provides SHA512 data add, finalize, and initialize Hash functions.

crypto's People

Contributors

aethaniel avatar himanshuseth-microchip avatar jiteshkambojmchp avatar kilzerk avatar lkgarner23 avatar martinrbowman avatar microchip-gfx avatar mratre avatar niyasmchp avatar pwrightmchp avatar rohitelectrical avatar vppillai avatar zzelevl avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

crypto's Issues

PIC32MZ hardware support throws ASYNC_OP_E

For my project I wanted SHA256 support and the random number generator. In the harmony configurator I enabled hardware support for both my requirements.

I looked in to the documentation and found the following:

  1. RNG
#define RANDOM_BYTE_SZ 32

int           ret;
CRYPT_RNG_CTX mcRng;
byte          out[RANDOM_BYTE_SZ];

ret = CRYPT_RNG_Initialize(&mcRng);
ret = CRYPT_RNG_BlockGenerate(&mcRng, out, RANDOM_BYTE_SZ);

The initialize function fails with error code -209 (DRBG_CONT_FIPS_E).
But the initialize function tries to preform a sha256 operations with fails which I will mention below.

  1. SHA256
CRYPT_SHA_CTX sha;
uint8_t shaSum[SHA_DIGEST_SIZE];

CRYPT_SHA_Initialize(&sha);
CRYPT_SHA_DataAdd(&sha, buffer, sizeof(buffer));
CRYPT_SHA_Finalize(&sha, shaSum);

The initialize function fails with error code -245 (ASYNC_OP_E).

After going line by line with the debugger I stumbled on the while-wait loop that times out in pic32mz-crypt.c Pic32Crypto()

        /* Software Reset the Crypto Engine */
        CECON = 1 << 6;
        while (CECON);

        /* Clear the interrupt flags */
        CEINTSRC = 0xF;

        /* Run the engine */
        CEBDPADDR = (unsigned int)KVA_TO_PA(&bd);
        CEINTEN = 0x07; /* enable DMA Packet Completion Interrupt */

        /* input swap, enable BD fetch and start DMA */
    #if PIC32_NO_OUT_SWAP
        CECON = 0x25;
    #else
        CECON = 0xa5; /* bit 7 = enable out swap */
    #endif

        /* wait for operation to complete */
        while (CEINTSRCbits.PKTIF == 0 && --timeout > 0) {};

        /* Clear the interrupt flags */
        CEINTSRC = 0xF;

        /* check for errors */
        if (CESTATbits.ERROP || timeout <= 0) {
        #if 0
            printf("PIC32 Crypto: ERROP %x, ERRPHASE %x, TIMEOUT %s\n",
                CESTATbits.ERROP, CESTATbits.ERRPHASE, timeout <= 0 ? "yes" : "no");
        #endif
            ret = ASYNC_OP_E;
        }

the CEINTSRCbits.PKTIF seems to be never set to 1.
I looked up what this function does and compared it with the PIC32MZ datasheet and this function seems to enable al the right registers.

Maybe I forgot to setup/initialize something in the project but I can't find anything in the Harmony documentation files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.