void v_encrypt_test(void) { uint8 k_priv[BITS / 8], k_pub[BITS / 8], k_n[BITS / 8], cipher[BITS / 8], plain[BITS / 8], decode[BITS / 8], i; printf("testing RSA-crypto\n"); v_e_connect_create_key(k_pub, k_priv, k_n); /* exit(0);*/ printf("key pair generated, encrypting something\n"); memset(plain, 0, sizeof plain); strcpy(plain, "This is some text to encrypt, to give it something to chew on."); printf("plain: %02X (%u)\n", plain[0], strlen(plain)); v_e_connect_encrypt(cipher, plain, k_pub, k_n); printf("plain: %02X, cipher: %02X\n", plain[0], cipher[0]); v_e_connect_encrypt(decode, cipher, k_priv, k_n); printf("decoded: %02X: '", decode[0]); for(i = 0; decode[i] != 0; i++) putchar(decode[i]); printf("'\n"); /* printf("\npublic key: "); v_bignum_print_hex_lf(k_public); printf("private key: "); v_bignum_print_hex_lf(k_private); v_bignum_set_string(msg, "123"); gettimeofday(&t1, NULL); v_bignum_pow_mod(msg, k_private, k_n); gettimeofday(&t2, NULL); printf("encrypted: "); v_bignum_print_hex_lf(msg); printf("encrypted %u bits in %g s\n", BITS, t2.tv_sec - t1.tv_sec + 1.0E-6 * (t2.tv_usec - t1.tv_usec)); gettimeofday(&t1, NULL); v_bignum_pow_mod(msg, k_public, k_n); gettimeofday(&t2, NULL); printf("decrypted: "); v_bignum_print_hex_lf(msg); printf("decrypted %u bits in %g s\n", BITS, t2.tv_sec - t1.tv_sec + 1.0E-6 * (t2.tv_usec - t1.tv_usec)); exit(0); *//* v_e_encrypt(cipher, plain, &k_private, &k_n); printf("encrypted data: "); for(i = 0; i < sizeof cipher; i++) printf("%c", isalnum(cipher[i]) ? cipher[i] : '?'); printf("\n\n"); printf("decrypting\n"); v_e_encrypt(decode, cipher, &k_public, &k_n); printf("decrypted data: "); for(i = 0; i < sizeof cipher; i++) printf("%c", isalnum(decode[i]) ? decode[i] : '?'); printf("\n\n"); */ }
void verse_host_id_create(uint8 *id) { v_e_connect_create_key(&id[V_ENCRYPTION_LOGIN_PRIVATE_START], &id[V_ENCRYPTION_LOGIN_PUBLIC_START], &id[V_ENCRYPTION_LOGIN_N_START]); }