Commit 9408cff6 by Enrico Pozzobon

corrected esp32 interrupts

parent 33472d31
...@@ -61,11 +61,16 @@ void setup() { ...@@ -61,11 +61,16 @@ void setup() {
memset(ad, 0, MAX_BYTES); memset(ad, 0, MAX_BYTES);
memset(m, 0, MAX_BYTES); memset(m, 0, MAX_BYTES);
memset(c, 0, MAX_BYTES); memset(c, 0, MAX_BYTES);
mlen = 8;
adlen = 0;
crypto_aead_encrypt(c, &clen, m, mlen, ad, adlen, nsec, npub, k);
crypto_aead_decrypt(m, &mlen, nsec, c, clen, ad, adlen, npub, k);
SerialOut.print("Hello, World!"); SerialOut.print("Hello, World!");
} }
void loop() { void loop() {
int res; int res;
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
uint16_t len = uartp_recv(cmdbuf, CMDBUF_LEN - 1); uint16_t len = uartp_recv(cmdbuf, CMDBUF_LEN - 1);
uint8_t action = cmdbuf[0]; uint8_t action = cmdbuf[0];
if (len == 0 || len > CMDBUF_LEN - 1) if (len == 0 || len > CMDBUF_LEN - 1)
...@@ -82,22 +87,18 @@ void loop() { ...@@ -82,22 +87,18 @@ void loop() {
case 'p': my_assert(l == CRYPTO_NPUBBYTES); memcpy(npub, var, l); break; case 'p': my_assert(l == CRYPTO_NPUBBYTES); memcpy(npub, var, l); break;
case 's': my_assert(l == CRYPTO_NSECBYTES); memcpy(nsec, var, l); break; case 's': my_assert(l == CRYPTO_NSECBYTES); memcpy(nsec, var, l); break;
case 'e': case 'e':
noInterrupts(); portENTER_CRITICAL(&mux);
asm("nop");
digitalWrite(CRYPTO_BUSY, LOW); digitalWrite(CRYPTO_BUSY, LOW);
res = crypto_aead_encrypt(c, &clen, m, mlen, ad, adlen, nsec, npub, k); res = crypto_aead_encrypt(c, &clen, m, mlen, ad, adlen, nsec, npub, k);
digitalWrite(CRYPTO_BUSY, HIGH); digitalWrite(CRYPTO_BUSY, HIGH);
asm("nop"); portEXIT_CRITICAL(&mux);
interrupts();
break; break;
case 'd': case 'd':
noInterrupts(); portENTER_CRITICAL(&mux);
asm("nop");
digitalWrite(CRYPTO_BUSY, LOW); digitalWrite(CRYPTO_BUSY, LOW);
res = crypto_aead_decrypt(m, &mlen, nsec, c, clen, ad, adlen, npub, k); res = crypto_aead_decrypt(m, &mlen, nsec, c, clen, ad, adlen, npub, k);
digitalWrite(CRYPTO_BUSY, HIGH); digitalWrite(CRYPTO_BUSY, HIGH);
asm("nop"); portEXIT_CRITICAL(&mux);
interrupts();
break; break;
case'M': var = m; rl = mlen; break; case'M': var = m; rl = mlen; break;
case'C': var = c; rl = clen; break; case'C': var = c; rl = clen; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment