CryptoDataDecrypt,
Ed25519Sign,
Ed25519Verify,
- Ed25519NewKeyPair
+ Ed25519NewKeyPair,
+ Ed25519KeyPairPublicKey
}
impl SystemClauseType {
&SystemClauseType::CryptoDataDecrypt => clause_name!("$crypto_data_decrypt"),
&SystemClauseType::Ed25519Sign => clause_name!("$ed25519_sign"),
&SystemClauseType::Ed25519Verify => clause_name!("$ed25519_verify"),
- &SystemClauseType::Ed25519NewKeyPair => clause_name!("$ed25519_new_keypair")
+ &SystemClauseType::Ed25519NewKeyPair => clause_name!("$ed25519_new_keypair"),
+ &SystemClauseType::Ed25519KeyPairPublicKey => clause_name!("$ed25519_keypair_public_key")
}
}
("$ed25519_sign", 3) => Some(SystemClauseType::Ed25519Sign),
("$ed25519_verify", 3) => Some(SystemClauseType::Ed25519Verify),
("$ed25519_new_keypair", 1) => Some(SystemClauseType::Ed25519NewKeyPair),
+ ("$ed25519_keypair_public_key", 2) => Some(SystemClauseType::Ed25519KeyPairPublicKey),
_ => None,
}
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
:- module(crypto,
- [hex_bytes/2, % ?Hex, ?Bytes
- crypto_n_random_bytes/2, % +N, -Bytes
- crypto_data_hash/3, % +Data, -Hash, +Options
- crypto_data_hkdf/4, % +Data, +Length, -Bytes, +Options
- crypto_password_hash/2, % +Password, ?Hash
- crypto_password_hash/3, % +Password, -Hash, +Options
- crypto_data_encrypt/6, % +PlainText, +Algorithm, +Key, +IV, -CipherText, +Options
- crypto_data_decrypt/6, % +CipherText, +Algorithm, +Key, +IV, -PlainText, +Options
- ed25519_new_keypair/1, % -KeyPair
- ed25519_sign/4, % +PrivateKey, +Data, -Signature, +Options
- ed25519_verify/4, % +PublicKey, +Data, -Signature, +Options
- crypto_name_curve/2, % +Name, -Curve
- crypto_curve_order/2, % +Curve, -Order
- crypto_curve_generator/2, % +Curve, -Generator
- crypto_curve_scalar_mult/4 % +Curve, +Scalar, +Point, -Result
+ [hex_bytes/2, % ?Hex, ?Bytes
+ crypto_n_random_bytes/2, % +N, -Bytes
+ crypto_data_hash/3, % +Data, -Hash, +Options
+ crypto_data_hkdf/4, % +Data, +Length, -Bytes, +Options
+ crypto_password_hash/2, % +Password, ?Hash
+ crypto_password_hash/3, % +Password, -Hash, +Options
+ crypto_data_encrypt/6, % +PlainText, +Algorithm, +Key, +IV, -CipherText, +Options
+ crypto_data_decrypt/6, % +CipherText, +Algorithm, +Key, +IV, -PlainText, +Options
+ ed25519_new_keypair/1, % -KeyPair
+ ed25519_keypair_public_key/2, % +KeyPair, +PublicKey
+ ed25519_sign/4, % +PrivateKey, +Data, -Signature, +Options
+ ed25519_verify/4, % +PublicKey, +Data, -Signature, +Options
+ crypto_name_curve/2, % +Name, -Curve
+ crypto_curve_order/2, % +Curve, -Order
+ crypto_curve_generator/2, % +Curve, -Generator
+ crypto_curve_scalar_mult/4 % +Curve, +Scalar, +Point, -Result
]).
:- use_module(library(error)).
ed25519_new_keypair(Pair) :-
'$ed25519_new_keypair'(Pair).
+ed25519_keypair_public_key(Pair0, PublicKey) :-
+ encoding_bytes(octet, Pair0, Pair),
+ '$ed25519_keypair_public_key'(Pair, PublicKey).
+
ed25519_sign(Key0, Data0, Signature, Options) :-
options_data_bytes(Options, Data0, Data),
encoding_bytes(octet, Key0, Key),
use crate::crossterm::terminal::{enable_raw_mode, disable_raw_mode};
use ring::rand::{SecureRandom, SystemRandom};
-use ring::{digest,hkdf,pbkdf2,aead,signature};
+use ring::{digest,hkdf,pbkdf2,aead,signature::{self,KeyPair}};
use ripemd160::{Ripemd160, Digest};
use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512};
use blake2::{Blake2s, Blake2b};
self.unify(self[temp_v!(1)], complete_string);
}
+ &SystemClauseType::Ed25519KeyPairPublicKey => {
+ let stub1 = MachineError::functor_stub(clause_name!("ed25519_keypair_public_key"), 2);
+ let bytes = self.integers_to_bytevec(temp_v!(1), stub1);
+
+ let key_pair = match signature::Ed25519KeyPair::from_pkcs8_maybe_unchecked(&bytes) {
+ Ok(kp) => { kp }
+ _ => { self.fail = true; return Ok(()); }
+ };
+
+ let complete_string = {
+ let buffer = String::from_iter(key_pair.public_key().as_ref().iter().map(|b| *b as char));
+ self.heap.put_complete_string(&buffer)
+ };
+
+ self.unify(self[temp_v!(2)], complete_string);
+ }
&SystemClauseType::Ed25519Sign => {
let stub1 = MachineError::functor_stub(clause_name!("ed25519_sign"), 4);
let key = self.integers_to_bytevec(temp_v!(1), stub1);