RSA wrapper.
This commit is contained in:
parent
de570d5594
commit
2ecb8e25f0
@ -41,6 +41,10 @@ var emscAlloc = {
|
||||
data_to_string_alloc: getEmsc('GNUNET_STRINGS_data_to_string_alloc', 'number', ['number', 'number']),
|
||||
purpose_create: getEmsc('TALER_WRALL_purpose_create', 'number', ['number', 'number', 'number']),
|
||||
rsa_blind: getEmsc('GNUNET_CRYPTO_rsa_blind', 'number', ['number', 'number', 'number', 'number']),
|
||||
rsa_blinding_key_create: getEmsc('GNUNET_CRYPTO_rsa_blinding_key_create', 'void', ['number']),
|
||||
rsa_blinding_key_encode: getEmsc('GNUNET_CRYPTO_rsa_blinding_key_encode', 'void', ['number', 'number']),
|
||||
rsa_blinding_key_decode: getEmsc('GNUNET_CRYPTO_rsa_blinding_key_decode', 'number', ['number', 'number']),
|
||||
rsa_public_key_decode: getEmsc('GNUNET_CRYPTO_rsa_public_key_decode', 'number', ['number', 'number']),
|
||||
malloc: (size) => Module._malloc(size),
|
||||
};
|
||||
var SignaturePurpose;
|
||||
@ -194,6 +198,20 @@ class EddsaPublicKey extends PackedArenaObject {
|
||||
size() { return 32; }
|
||||
}
|
||||
class RsaBlindingKey extends ArenaObject {
|
||||
static create(len, a) {
|
||||
let o = new RsaBlindingKey(a);
|
||||
o.nativePtr = emscAlloc.rsa_blinding_key_create(len);
|
||||
return o;
|
||||
}
|
||||
encode() {
|
||||
let ptr = emscAlloc.malloc(PTR_SIZE);
|
||||
let size = emscAlloc.rsa_blinding_key_encode(this.nativePtr, ptr);
|
||||
let res = new ByteArray(size, Module.getValue(ptr, '*'));
|
||||
let s = res.encode();
|
||||
emsc.free(ptr);
|
||||
res.destroy();
|
||||
return s;
|
||||
}
|
||||
destroy() {
|
||||
// TODO
|
||||
}
|
||||
@ -276,6 +294,14 @@ class WithdrawRequestPS extends SignatureStruct {
|
||||
}
|
||||
}
|
||||
class RsaPublicKey extends ArenaObject {
|
||||
static decode(s, a) {
|
||||
let obj = new RsaPublicKey(a);
|
||||
let hstr = emscAlloc.malloc(s.length + 1);
|
||||
Module.writeStringToMemory(s, hstr);
|
||||
obj.nativePtr = emscAlloc.rsa_public_key_decode(hstr, s.length);
|
||||
emsc.free(hstr);
|
||||
return obj;
|
||||
}
|
||||
destroy() {
|
||||
emsc.rsa_public_key_free(this.nativePtr);
|
||||
this.nativePtr = 0;
|
||||
|
@ -85,6 +85,18 @@ var emscAlloc = {
|
||||
rsa_blind: getEmsc('GNUNET_CRYPTO_rsa_blind',
|
||||
'number',
|
||||
['number', 'number', 'number', 'number']),
|
||||
rsa_blinding_key_create: getEmsc('GNUNET_CRYPTO_rsa_blinding_key_create',
|
||||
'void',
|
||||
['number']),
|
||||
rsa_blinding_key_encode: getEmsc('GNUNET_CRYPTO_rsa_blinding_key_encode',
|
||||
'void',
|
||||
['number', 'number']),
|
||||
rsa_blinding_key_decode: getEmsc('GNUNET_CRYPTO_rsa_blinding_key_decode',
|
||||
'number',
|
||||
['number', 'number']),
|
||||
rsa_public_key_decode: getEmsc('GNUNET_CRYPTO_rsa_public_key_decode',
|
||||
'number',
|
||||
['number', 'number']),
|
||||
malloc: (size: number) => Module._malloc(size),
|
||||
};
|
||||
|
||||
@ -280,6 +292,22 @@ class EddsaPublicKey extends PackedArenaObject {
|
||||
|
||||
|
||||
class RsaBlindingKey extends ArenaObject {
|
||||
static create(len: number, a?: Arena) {
|
||||
let o = new RsaBlindingKey(a);
|
||||
o.nativePtr = emscAlloc.rsa_blinding_key_create(len);
|
||||
return o;
|
||||
}
|
||||
|
||||
encode(): string {
|
||||
let ptr = emscAlloc.malloc(PTR_SIZE);
|
||||
let size = emscAlloc.rsa_blinding_key_encode(this.nativePtr, ptr);
|
||||
let res = new ByteArray(size, Module.getValue(ptr, '*'));
|
||||
let s = res.encode();
|
||||
emsc.free(ptr);
|
||||
res.destroy();
|
||||
return s;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
// TODO
|
||||
}
|
||||
@ -375,6 +403,15 @@ class WithdrawRequestPS extends SignatureStruct {
|
||||
|
||||
|
||||
class RsaPublicKey extends ArenaObject {
|
||||
static decode(s: string, a?: Arena): RsaPublicKey {
|
||||
let obj = new RsaPublicKey(a);
|
||||
let hstr = emscAlloc.malloc(s.length + 1);
|
||||
Module.writeStringToMemory(s, hstr);
|
||||
obj.nativePtr = emscAlloc.rsa_public_key_decode(hstr, s.length);
|
||||
emsc.free(hstr);
|
||||
return obj;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
emsc.rsa_public_key_free(this.nativePtr);
|
||||
this.nativePtr = 0;
|
||||
@ -384,7 +421,7 @@ class RsaPublicKey extends ArenaObject {
|
||||
|
||||
function rsaBlind(hashCode: HashCode,
|
||||
blindingKey: RsaBlindingKey,
|
||||
pkey: EddsaPublicKey,
|
||||
pkey: RsaPublicKey,
|
||||
arena?: Arena): ByteArray
|
||||
{
|
||||
let ptr = emscAlloc.malloc(PTR_SIZE);
|
||||
|
@ -115,9 +115,12 @@ function withdraw(denom, reserve, mint) {
|
||||
denom_pub: denom.denom_pub,
|
||||
reserve_pub: reserve.reserve_pub,
|
||||
};
|
||||
let coinPub = EddsaPrivateKey.create();
|
||||
// create RSA blinding key
|
||||
// blind coin
|
||||
let denomPub = RsaPublicKey.decode(denom.denom_pub);
|
||||
let coinPriv = EddsaPrivateKey.create();
|
||||
let coinPub = coinPriv.getPublicKey();
|
||||
let blindingFactor = RsaBlindingKey.create(1024);
|
||||
let pubHash = coinPub.hash();
|
||||
let ev = rsaBlind(pubHash, blindingFactor, denomPub);
|
||||
// generate signature
|
||||
}
|
||||
/**
|
||||
|
@ -128,9 +128,13 @@ function withdraw(denom, reserve, mint) {
|
||||
denom_pub: denom.denom_pub,
|
||||
reserve_pub: reserve.reserve_pub,
|
||||
};
|
||||
let coinPub = EddsaPrivateKey.create();
|
||||
// create RSA blinding key
|
||||
// blind coin
|
||||
let denomPub = RsaPublicKey.decode(denom.denom_pub);
|
||||
let coinPriv = EddsaPrivateKey.create();
|
||||
let coinPub = coinPriv.getPublicKey();
|
||||
let blindingFactor = RsaBlindingKey.create(1024);
|
||||
let pubHash = coinPub.hash();
|
||||
let ev = rsaBlind(pubHash, blindingFactor, denomPub);
|
||||
|
||||
// generate signature
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user