diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-05-25 21:24:21 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-05-25 21:24:28 +0200 |
commit | 34b65e2ef704fdc4b8c1c24ec86303a75f7ca59d (patch) | |
tree | 52b182da2650b045fb89d51e9422aaa54a6db95e /lib/wallet | |
parent | 5dd21b109d219092b147e112c1f587af24723e72 (diff) |
support for derived blinding keys
Diffstat (limited to 'lib/wallet')
-rw-r--r-- | lib/wallet/cryptoLib.ts | 4 | ||||
-rw-r--r-- | lib/wallet/db.ts | 2 | ||||
-rw-r--r-- | lib/wallet/emscriptif.ts | 58 |
3 files changed, 31 insertions, 33 deletions
diff --git a/lib/wallet/cryptoLib.ts b/lib/wallet/cryptoLib.ts index 967fc23c8..c18c9d74d 100644 --- a/lib/wallet/cryptoLib.ts +++ b/lib/wallet/cryptoLib.ts @@ -70,7 +70,7 @@ namespace RpcFunctions { let denomPub = native.RsaPublicKey.fromCrock(denom.denom_pub); let coinPriv = native.EddsaPrivateKey.create(); let coinPub = coinPriv.getPublicKey(); - let blindingFactor = native.RsaBlindingKey.create(1024); + let blindingFactor = native.RsaBlindingKeySecret.create(); let pubHash: native.HashCode = coinPub.hash(); let ev: native.ByteArray = native.rsaBlind(pubHash, blindingFactor, @@ -158,7 +158,7 @@ namespace RpcFunctions { export function rsaUnblind(sig, bk, pk): string { let denomSig = native.rsaUnblind(native.RsaSignature.fromCrock(sig), - native.RsaBlindingKey.fromCrock(bk), + native.RsaBlindingKeySecret.fromCrock(bk), native.RsaPublicKey.fromCrock(pk)); return denomSig.encode().toCrock() } diff --git a/lib/wallet/db.ts b/lib/wallet/db.ts index 0111a6c6e..78534b567 100644 --- a/lib/wallet/db.ts +++ b/lib/wallet/db.ts @@ -25,7 +25,7 @@ */ const DB_NAME = "taler"; -const DB_VERSION = 6; +const DB_VERSION = 7; /** * Return a promise that resolves diff --git a/lib/wallet/emscriptif.ts b/lib/wallet/emscriptif.ts index 4ec029e52..aea98f50f 100644 --- a/lib/wallet/emscriptif.ts +++ b/lib/wallet/emscriptif.ts @@ -98,6 +98,9 @@ var emsc = { rsa_blinding_key_destroy: getEmsc('GNUNET_CRYPTO_rsa_blinding_key_free', 'void', ['number']), + random_block: getEmsc('GNUNET_CRYPTO_random_block', + 'void', + ['number', 'number', 'number']), }; var emscAlloc = { @@ -394,6 +397,10 @@ export class Amount extends ArenaObject { } +/** + * Managed reference to a contiguous block of memory in the Emscripten heap. + * Should contain only data, not pointers. + */ abstract class PackedArenaObject extends ArenaObject { abstract size(): number; @@ -401,6 +408,10 @@ abstract class PackedArenaObject extends ArenaObject { super(a); } + randomize(qual: RandomQuality = RandomQuality.STRONG): void { + emsc.random_block(qual, this.nativePtr, this.size()); + } + toCrock(): string { var d = emscAlloc.data_to_string_alloc(this.nativePtr, this.size()); var s = Module.Pointer_stringify(d); @@ -569,21 +580,24 @@ function makeToCrock(encodeFn: (po: number, return toCrock; } -export 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; +export class RsaBlindingKeySecret extends PackedArenaObject { + size() { + return 32; } - static fromCrock: (s: string, a?: Arena) => RsaBlindingKey; - toCrock = makeToCrock(emscAlloc.rsa_blinding_key_encode); - - destroy() { - // TODO + /** + * Create a random blinding key secret. + */ + static create(a?: Arena): RsaBlindingKeySecret { + let o = new RsaBlindingKeySecret(a); + o.alloc(); + o.randomize(); + return o; } + + static fromCrock: (string) => RsaBlindingKeySecret; } -mixinStatic(RsaBlindingKey, makeFromCrock(emscAlloc.rsa_blinding_key_decode)); +mixinStatic(RsaBlindingKeySecret, fromCrock); export class HashCode extends PackedArenaObject { @@ -593,23 +607,7 @@ export class HashCode extends PackedArenaObject { static fromCrock: (s: string) => HashCode; - random(qualStr: string) { - let qual: RandomQuality; - switch (qualStr) { - case "weak": - qual = RandomQuality.WEAK; - break; - case "strong": - case null: - case undefined: - qual = RandomQuality.STRONG; - break; - case "nonce": - qual = RandomQuality.NONCE; - break; - default: - throw Error(`unknown crypto quality: ${qual}`); - } + random(qual: RandomQuality = RandomQuality.STRONG) { this.alloc(); emsc.hash_create_random(qual, this.nativePtr); } @@ -955,7 +953,7 @@ mixin(RsaSignature, makeEncode(emscAlloc.rsa_signature_encode)); export function rsaBlind(hashCode: HashCode, - blindingKey: RsaBlindingKey, + blindingKey: RsaBlindingKeySecret, pkey: RsaPublicKey, arena?: Arena): ByteArray { let ptr = emscAlloc.malloc(PTR_SIZE); @@ -997,7 +995,7 @@ export function eddsaVerify(purposeNum: number, export function rsaUnblind(sig: RsaSignature, - bk: RsaBlindingKey, + bk: RsaBlindingKeySecret, pk: RsaPublicKey, a?: Arena): RsaSignature { let x = new RsaSignature(a); |