GithubHelp home page GithubHelp logo

Comments (1)

daricht avatar daricht commented on July 28, 2024

I think I figured it out! I didn't think you'd have to reset the key iv and counter each time...

If im not mistaken this code is working now:

#include <string.h>
#include "ChaCha.h"
#include "Crypto.h"
#include "utility/EndianUtil.h"
#include "utility/ProgMemUtil.h"
#include "utility/RotateUtil.h"
#define MAX_CIPHERTEXT_SIZE 32
ChaCha chacha;

const int msgLen = 32;

int size =5;
byte iv[8] = {101,102,103,104,105,106,107,108};
byte counter[8] = {109, 110, 111, 112, 113, 114, 115, 116};
byte plaintext[5] = {'#','j','0','1','G'};
byte cypher[5];
byte key[24] = {0x32, 0x62, 0x37, 0x65, 0x31, 0x35, 0x31, 0x36, 0x32, 0x38, 0x61, 0x65, 0x64, 0x32, 0x61, 0x36, 0x61, 0x62, 0x66, 0x37, 0x31, 0x35, 0x38, 0x39};
byte decrypted[5];

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

}

void loop(){

chacha.clear();
chacha.setKey(key, 24);
chacha.setIV(iv,8);
chacha.setCounter(counter,8);
Serial.println("####");
for (int i = 0; i < sizeof(plaintext); i++) {Serial.printf("%c", plaintext[i]);}Serial.println();
chacha.encrypt(cypher, plaintext, sizeof(plaintext));
for (int i = 0; i < sizeof(cypher); i++) {Serial.printf("%c", cypher[i]);}Serial.println();

chacha.setKey(key, 24);
chacha.setIV(iv,8);
chacha.setCounter(counter,8);

chacha.decrypt(decrypted, cypher, sizeof(cypher));
for (int i = 0; i < sizeof(decrypted); i++) {Serial.printf("%c", decrypted[i]);}Serial.println();
delay(1000);
}

from arduinolibs.

Related Issues (20)

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.