Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (34 sloc) 1.09 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sodium.h>
/* Generated by crypter */
/* Provides ciphertext, ciphertext_len, nonce and salt */
#include "encrypted.h"
int main(int argc, char *argv[]) {
if (sodium_init() < 0) {
fprintf(stderr, "Cannot initialise libsodium!\n");
exit(1);
}
if (argc != 2) {
fprintf(stderr, "Usage: %s <password>\n", argv[0]);
exit(1);
}
char *password = argv[1];
/* Use argon2 to convert password to a full size key */
unsigned char key[crypto_secretbox_KEYBYTES];
if (crypto_pwhash(key, sizeof key, password, strlen(password), salt,
crypto_pwhash_OPSLIMIT_INTERACTIVE, crypto_pwhash_MEMLIMIT_INTERACTIVE,
crypto_pwhash_ALG_DEFAULT) != 0) {
fprintf(stderr, "Key derivation failed\n");
exit(1);
}
unsigned char *decrypted = alloca(ciphertext_len); /* slightly longer than needed */
if (crypto_secretbox_open_easy(decrypted, ciphertext, ciphertext_len, nonce, key) != 0) {
printf("Decryption failed!\n");
exit(1);
}
/* Execute it */
int (*code)() = (int(*)())decrypted;
code();
}