Commit ed417d58 by Enrico Pozzobon

better input validation in linux template

parent 29172747
......@@ -111,10 +111,8 @@ int main() {
case 'e':
if (k == NULL || c == NULL) {
fprintf(stderr, c == NULL ? "Missing ciphertext buffer\r\n" : "Missing key\r\n");
return 3;
}
case 'd':
/*
fprintf(stderr, "mlen = %llu\r\n", mlen);
fprintf(stderr, "m = "); FPRINTF_HEX(stderr, m, mlen); fprintf(stderr, "\r\n");
fprintf(stderr, "adlen = %llu\r\n", adlen);
......@@ -125,22 +123,42 @@ int main() {
fprintf(stderr, "ns = "); FPRINTF_HEX(stderr, nsec, nslen); fprintf(stderr, "\r\n");
fprintf(stderr, "klen = %llu\r\n", klen);
fprintf(stderr, "k = "); FPRINTF_HEX(stderr, k, klen); fprintf(stderr, "\r\n");
*/
if (k == NULL) {
fprintf(stderr, "Missing key\r\n");
return 3;
}
fprintf(stderr, "Starting encryption\r\n");
res = crypto_aead_encrypt(c, &clen,
m, mlen, ad, adlen, nsec, npub, k);
fprintf(stderr, "encryption finished %d\r\n", res);
break;
case 'd':
if (m == NULL || k == NULL) {
fprintf(stderr, m == NULL ? "Missing message buffer\r\n" : "Missing key\r\n");
if (npub == NULL) {
fprintf(stderr, "Missing nonce\r\n");
return 3;
}
fprintf(stderr, "starting decryption\r\n");
res = crypto_aead_decrypt(m, &mlen,
nsec, c, clen, ad, adlen, npub, k);
fprintf(stderr, "decryption finished %d\r\n", res);
if (action == 'e') {
if (c == NULL) {
fprintf(stderr, "Missing ciphertext buffer\r\n");
return 3;
}
fprintf(stderr, "Starting encryption\r\n");
res = crypto_aead_encrypt(c, &clen,
m, mlen, ad, adlen, nsec, npub, k);
fprintf(stderr, "encryption finished %d\r\n", res);
} else if (action == 'd') {
if (m == NULL) {
fprintf(stderr, "Missing message buffer\r\n");
return 3;
}
fprintf(stderr, "starting decryption\r\n");
res = crypto_aead_decrypt(m, &mlen,
nsec, c, clen, ad, adlen, npub, k);
fprintf(stderr, "decryption finished %d\r\n", res);
}
break;
default:
......
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