1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
/*
20140225
20241210 - reformated using clang-format
Jan Mojzis
Public domain.
*/
#include "purge.h"
#include "bug.h"
#include "str.h"
#include "sshcrypto.h"
/*
Initialize and check *MAX constants
*/
void sshcrypto_init(void) {
long long i;
/* kex */
for (i = 0; sshcrypto_kexs[i].name; ++i) {
if (sshcrypto_kexs[i].kem_publickeybytes > sshcrypto_kem_PUBLICKEYMAX)
bug_inval();
if (sshcrypto_kexs[i].kem_ciphertextbytes > sshcrypto_kem_CIPHERTEXTMAX)
bug_inval();
if (sshcrypto_kexs[i].kem_bytes > sshcrypto_kem_MAX) bug_inval();
if (sshcrypto_kexs[i].hash_bytes > sshcrypto_hash_MAX) bug_inval();
}
/* key */
for (i = 0; sshcrypto_keys[i].name; ++i) {
if (sshcrypto_keys[i].sign_publickeybytes > sshcrypto_sign_PUBLICKEYMAX)
bug_inval();
if (sshcrypto_keys[i].sign_secretkeybytes > sshcrypto_sign_SECRETKEYMAX)
bug_inval();
if (sshcrypto_keys[i].sign_bytes > sshcrypto_sign_MAX) bug_inval();
if (str_len(sshcrypto_keys[i].name) + 1 > sshcrypto_sign_NAMEMAX)
bug_inval();
}
/* cipher */
for (i = 0; sshcrypto_ciphers[i].name; ++i) {
if (sshcrypto_ciphers[i].stream_keybytes > sshcrypto_cipher_KEYMAX)
bug_inval();
}
}
/*
Remove sentitive data from allocated memory.
*/
void sshcrypto_purge(void) {
long long i;
/* kex */
for (i = 0; sshcrypto_kexs[i].name; ++i) {
purge(&sshcrypto_kexs[i], sizeof(struct sshcrypto_kex));
}
/* key */
for (i = 0; sshcrypto_keys[i].name; ++i) {
purge(&sshcrypto_keys[i], sizeof(struct sshcrypto_key));
}
/* cipher */
for (i = 0; sshcrypto_ciphers[i].name; ++i) {
purge(&sshcrypto_ciphers[i], sizeof(struct sshcrypto_cipher));
}
}
|