L1VM - crypto keys
L1VM - crypto keys
I did write new code in the crypt module. Now public/private keys can be generated. For asymmetric key encryption. The functions are easy to handle. Here is a full example:
// crypto-lib-keys.l1com
//
// public/private key encrypt/decrypt demo
//
#include <intr.l1h>
(main func)
(set const-int64 1 zero 0)
(set const-int64 1 one 1)
(set const-byte 1 zerob 0)
(set const-byte 1 oneb 1)
(set byte 256 inarray)
(set byte 272 outarray)
(set byte 272 decryptarray)
(set byte 24 noncearray)
(set byte 32 alice_public_key)
(set byte 32 alice_private_key)
(set byte 32 bob_public_key)
(set byte 32 bob_private_key)
(set int64 1 count 0)
(set byte 1 i 0)
(set byte 1 c 0)
(set int64 1 ret 0)
(set int64 1 j 0)
(set int64 1 size 256)
(set byte 1 maxnumb 255)
(set int64 1 mode 0)
(set int64 1 f 0)
(set const-int64 1 Pinarray 0)
(set const-int64 1 Poutarray 0)
(set const-int64 1 Pkeystr 0)
(set const-int64 1 Pdecryptarray 0)
(set const-int64 1 Pnoncearray 0)
(set const-int64 1 Palice_public_key 0)
(set const-int64 1 Palice_private_key 0)
(set const-int64 1 Pbob_public_key 0)
(set const-int64 1 Pbob_private_key 0)
(set string s okstr "crypt decrypt/encrypt ok!")
(set string s errstr "crypt decrypt/encrypt ERROR!")
(set string s genkeysstr "generate key pairs for alice and bob.")
(set string s error_encryptstr "ERROR encrypting message!")
(set string s error_decryptstr "ERROR decrypting message!")
(set string s sepstr ": ")
(inarray Pinarray pointer)
(outarray Poutarray pointer)
(decryptarray Pdecryptarray pointer)
(noncearray Pnoncearray pointer)
(alice_public_key Palice_public_key pointer)
(alice_private_key Palice_private_key pointer)
(bob_public_key Pbob_public_key pointer)
(bob_private_key Pbob_private_key pointer)
(zero :crypto_init !)
(zero j =)
(zerob i =)
(for-loop)
(((j size <) f =) f for)
print_i (j)
print_s (sepstr)
(i inarray [ j ] =)
print_i (i)
print_n
//(reset-reg)
((i oneb +) i =)
((j one +) j =)
(next)
print_n
print_s (genkeysstr)
print_n
// generate key pairs for alice and bob
(Palice_public_key Palice_private_key :generate_keys !)
(Pbob_public_key Pbob_private_key :generate_keys !)
// encrypt message for bob
(Pinarray size Poutarray Pnoncearray Pbob_public_key Palice_private_key :encrypt_message !)
(ret stpop)
(((ret zero !=) f =) f if)
print_s (error_encryptstr)
print_n
(endif)
// bob decrypts the message
(Poutarray size Pdecryptarray Pnoncearray Palice_public_key Pbob_private_key :decrypt_message !)
(ret stpop)
(((ret zero !=) f =) f if)
print_s (error_decryptstr)
print_n
(endif)
(zerob i =)
(zero j =)
print_n
print_n
(zero j =)
(zerob i =)
(for-loop)
(((j size <) f =) f for)
print_i (j)
print_s (sepstr)
(decryptarray [ j ] c =)
print_i (c)
print_n
(reset-reg)
((i oneb +) i =)
((j one +) j =)
(next)
exit (zero)
(funcend)
#include <crypto.l1h>