#include #include #include #include #include #include "rnd.h" #include "die.h" #include "str.h" #include "crypto.h" #include "curve.h" #include "ioops.h" #include "config.h" #include "keypair.h" void generate_keypair(void) { struct passwd *pw = getpwuid(getuid()); unsigned char publickey[crypto_box_pub_key_size]; unsigned char secretkey[crypto_box_sec_key_size]; char file[128]; xmemset(publickey, 0, sizeof(publickey)); xmemset(secretkey, 0, sizeof(secretkey)); curve25519_selftest(); printf("Reading from %s (this may take a while) ...\n", HIG_ENTROPY_SOURCE); gen_key_bytes(secretkey, sizeof(secretkey)); crypto_scalarmult_curve25519_base(publickey, secretkey); slprintf(file, sizeof(file), "%s/%s", pw->pw_dir, FILE_PUBKEY); write_blob_or_die(file, publickey, sizeof(publickey)); printf("Public key written to %s!\n", file); slprintf(file, sizeof(file), "%s/%s", pw->pw_dir, FILE_PRIVKEY); write_blob_or_die(file, secretkey, sizeof(secretkey)); printf("Secret key written to %s!\n", file); xmemset(publickey, 0, sizeof(publickey)); xmemset(secretkey, 0, sizeof(secretkey)); } void verify_keypair(void) { int result; struct passwd *pw = getpwuid(getuid()); unsigned char publickey[crypto_box_pub_key_size]; unsigned char publicres[crypto_box_pub_key_size]; unsigned char secretkey[crypto_box_sec_key_size]; char file[128]; curve25519_selftest(); xmemset(publickey, 0, sizeof(publickey)); xmemset(publicres, 0, sizeof(publicres)); xmemset(secretkey, 0, sizeof(secretkey)); slprintf(file, sizeof(file), "%s/%s", pw->pw_dir, FILE_PUBKEY); read_blob_or_die(file, publickey, sizeof(publickey)); slprintf(file, sizeof(file), "%s/%s", pw->pw_dir, FILE_PRIVKEY); read_blob_or_die(file, secretkey, sizeof(secretkey)); crypto_scalarmult_curve25519_base(publicres, secretkey); result = crypto_verify_32(publicres, publickey); xmemset(publickey, 0, sizeof(publickey)); xmemset(publicres, 0, sizeof(publicres)); xmemset(secretkey, 0, sizeof(secretkey)); if (result) panic("Keypair is corrupt! You need to regenerate!\n"); } 7c4ab7b2a7e34a13e468311db4cd64'>diff
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2016-09-13 03:35:20 +0900
committerEric Anholt <eric@anholt.net>2016-10-06 11:53:35 -0700
commit57b9f569447c4ab7b2a7e34a13e468311db4cd64 (patch)
treee6719af0a19a7958327ec1f25df79c8bfee87116
parentc2cbc38b9715bd8318062e600668fc30e5a3fbfa (diff)
drm/vc4: cleanup with list_first_entry_or_null()
The combo of list_empty() check and return list_first_entry() can be replaced with list_first_entry_or_null(). Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Signed-off-by: Eric Anholt <eric@anholt.net>