Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.6 kB
14
Indexable
Never
mbedtls_ctr_drbg_context ctr_CTX;
mbedtls_pk_context RSA_ctx;




void setup(){
    Serial.begin(9600);



    int res = 0;

    Serial.println("___________________PROGRAM_START_________________________"); //We get a lot of fluffer at the start of the program


    //SPIFFS
    FileManager * spiff = new SPIFFSFileManager();

    /*
    auto * rsaCryptographer = new RSACryptographer();

    if(rsaCryptographer->generate_CTRX_context() != 0){
        Serial.println("Error generating CTR");
    }
    if(rsaCryptographer->generate_key() != 0){
        Serial.println("Error");
    }

    if(rsaCryptographer->validate_key() != 0){
        Serial.println("Error");
    }*/

    getready_CTRDRBG_context(&ctr_CTX);
    generate_keys_PK_context(&RSA_ctx,&ctr_CTX);

    unsigned char inputArray[30];
    unsigned char outputArray[4000];
    size_t oLen;

    fill_alphanumeric_unsignedString(inputArray,sizeof(inputArray));
    println_unsignedString(inputArray,sizeof(inputArray),CHR);

    res = mbedtls_pk_encrypt(&RSA_ctx, inputArray, sizeof(inputArray),  outputArray, &oLen,
                             sizeof(outputArray), mbedtls_ctr_drbg_random, &ctr_CTX);
    Serial.println(res);
    println_unsignedString(outputArray,sizeof(outputArray),CHR);
    res = mbedtls_pk_decrypt(&RSA_ctx, outputArray, sizeof(outputArray),  outputArray, &oLen,
                             sizeof(outputArray), mbedtls_ctr_drbg_random, &ctr_CTX);
    Serial.println(res);
    println_unsignedString(outputArray,oLen,CHR);