Fixed bug in nip44.c, was an error in ecdh_shared_secret. Added comments

This commit is contained in:
2025-08-17 11:29:07 -04:00
parent d8b342ca3f
commit 3ebfdc06c0
14 changed files with 15 additions and 69 deletions

View File

@@ -83,12 +83,6 @@ static int hex_to_bytes(const char* hex, unsigned char* bytes, size_t len) {
return 0;
}
static void bytes_to_hex(const unsigned char* bytes, size_t len, char* hex) {
for (size_t i = 0; i < len; i++) {
sprintf(hex + i * 2, "%02x", bytes[i]);
}
hex[len * 2] = '\0';
}
static int test_nip44_round_trip(const nip44_test_vector_t* tv) {
printf("Test: %s\n", tv->name);
@@ -364,31 +358,39 @@ int main() {
size_t num_vectors = sizeof(test_vectors) / sizeof(test_vectors[0]);
for (size_t i = 0; i < num_vectors; i++) {
total_tests++;
printf("Test #%d\n", total_tests);
if (test_nip44_round_trip(&test_vectors[i]) == 0) {
passed_tests++;
}
printf("\n");
}
// Test decryption vectors (cross-compatibility)
size_t num_decryption_vectors = sizeof(decryption_test_vectors) / sizeof(decryption_test_vectors[0]);
for (size_t i = 0; i < num_decryption_vectors; i++) {
total_tests++;
printf("Test #%d\n", total_tests);
if (test_nip44_decryption_vector(&decryption_test_vectors[i]) == 0) {
passed_tests++;
}
printf("\n");
}
// Test encryption variability (NIP-44 non-deterministic behavior)
total_tests++;
printf("Test #%d\n", total_tests);
if (test_nip44_encryption_variability() == 0) {
passed_tests++;
}
printf("\n");
// Test error conditions
total_tests++;
printf("Test #%d\n", total_tests);
if (test_nip44_error_conditions() == 0) {
passed_tests++;
}
printf("\n");
// Final results
printf("\nTest Results: %d/%d passed\n", passed_tests, total_tests);