diff options
author | Florian Dold <florian.dold@gmail.com> | 2015-12-14 08:54:59 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2015-12-14 08:54:59 +0100 |
commit | 2ecb8e25f07f2b5e8c848a8dbc5da05bdd289813 (patch) | |
tree | e5162dc017fa887582e308b55113fcd22c909e9f /extension | |
parent | de570d55943c1066cb03150cd904a2b57bdb5faf (diff) | |
download | wallet-core-2ecb8e25f07f2b5e8c848a8dbc5da05bdd289813.tar.xz |
RSA wrapper.
Diffstat (limited to 'extension')
-rw-r--r-- | extension/background/emscriptif.js | 26 | ||||
-rw-r--r-- | extension/background/emscriptif.ts | 39 | ||||
-rw-r--r-- | extension/background/wallet.js | 9 | ||||
-rw-r--r-- | extension/background/wallet.ts | 10 |
4 files changed, 77 insertions, 7 deletions
diff --git a/extension/background/emscriptif.js b/extension/background/emscriptif.js index 7f3a23f61..f90f41ec2 100644 --- a/extension/background/emscriptif.js +++ b/extension/background/emscriptif.js @@ -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; diff --git a/extension/background/emscriptif.ts b/extension/background/emscriptif.ts index 7a775d19a..ef14065a7 100644 --- a/extension/background/emscriptif.ts +++ b/extension/background/emscriptif.ts @@ -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); diff --git a/extension/background/wallet.js b/extension/background/wallet.js index 4f245588b..7011280fa 100644 --- a/extension/background/wallet.js +++ b/extension/background/wallet.js @@ -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 } /** diff --git a/extension/background/wallet.ts b/extension/background/wallet.ts index b04babb68..040b7b6a9 100644 --- a/extension/background/wallet.ts +++ b/extension/background/wallet.ts @@ -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 } |