support for derived blinding keys

This commit is contained in:
Florian Dold 2016-05-25 21:24:21 +02:00
parent 5dd21b109d
commit 34b65e2ef7
4 changed files with 43 additions and 45 deletions

File diff suppressed because one or more lines are too long

View File

@ -70,7 +70,7 @@ namespace RpcFunctions {
let denomPub = native.RsaPublicKey.fromCrock(denom.denom_pub); let denomPub = native.RsaPublicKey.fromCrock(denom.denom_pub);
let coinPriv = native.EddsaPrivateKey.create(); let coinPriv = native.EddsaPrivateKey.create();
let coinPub = coinPriv.getPublicKey(); let coinPub = coinPriv.getPublicKey();
let blindingFactor = native.RsaBlindingKey.create(1024); let blindingFactor = native.RsaBlindingKeySecret.create();
let pubHash: native.HashCode = coinPub.hash(); let pubHash: native.HashCode = coinPub.hash();
let ev: native.ByteArray = native.rsaBlind(pubHash, let ev: native.ByteArray = native.rsaBlind(pubHash,
blindingFactor, blindingFactor,
@ -158,7 +158,7 @@ namespace RpcFunctions {
export function rsaUnblind(sig, bk, pk): string { export function rsaUnblind(sig, bk, pk): string {
let denomSig = native.rsaUnblind(native.RsaSignature.fromCrock(sig), let denomSig = native.rsaUnblind(native.RsaSignature.fromCrock(sig),
native.RsaBlindingKey.fromCrock(bk), native.RsaBlindingKeySecret.fromCrock(bk),
native.RsaPublicKey.fromCrock(pk)); native.RsaPublicKey.fromCrock(pk));
return denomSig.encode().toCrock() return denomSig.encode().toCrock()
} }

View File

@ -25,7 +25,7 @@
*/ */
const DB_NAME = "taler"; const DB_NAME = "taler";
const DB_VERSION = 6; const DB_VERSION = 7;
/** /**
* Return a promise that resolves * Return a promise that resolves

View File

@ -98,6 +98,9 @@ var emsc = {
rsa_blinding_key_destroy: getEmsc('GNUNET_CRYPTO_rsa_blinding_key_free', rsa_blinding_key_destroy: getEmsc('GNUNET_CRYPTO_rsa_blinding_key_free',
'void', 'void',
['number']), ['number']),
random_block: getEmsc('GNUNET_CRYPTO_random_block',
'void',
['number', 'number', 'number']),
}; };
var emscAlloc = { 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 class PackedArenaObject extends ArenaObject {
abstract size(): number; abstract size(): number;
@ -401,6 +408,10 @@ abstract class PackedArenaObject extends ArenaObject {
super(a); super(a);
} }
randomize(qual: RandomQuality = RandomQuality.STRONG): void {
emsc.random_block(qual, this.nativePtr, this.size());
}
toCrock(): string { toCrock(): string {
var d = emscAlloc.data_to_string_alloc(this.nativePtr, this.size()); var d = emscAlloc.data_to_string_alloc(this.nativePtr, this.size());
var s = Module.Pointer_stringify(d); var s = Module.Pointer_stringify(d);
@ -569,21 +580,24 @@ function makeToCrock(encodeFn: (po: number,
return toCrock; return toCrock;
} }
export class RsaBlindingKey extends ArenaObject { export class RsaBlindingKeySecret extends PackedArenaObject {
static create(len: number, a?: Arena) { size() {
let o = new RsaBlindingKey(a); return 32;
o.nativePtr = emscAlloc.rsa_blinding_key_create(len); }
/**
* Create a random blinding key secret.
*/
static create(a?: Arena): RsaBlindingKeySecret {
let o = new RsaBlindingKeySecret(a);
o.alloc();
o.randomize();
return o; return o;
} }
static fromCrock: (s: string, a?: Arena) => RsaBlindingKey; static fromCrock: (string) => RsaBlindingKeySecret;
toCrock = makeToCrock(emscAlloc.rsa_blinding_key_encode);
destroy() {
// TODO
}
} }
mixinStatic(RsaBlindingKey, makeFromCrock(emscAlloc.rsa_blinding_key_decode)); mixinStatic(RsaBlindingKeySecret, fromCrock);
export class HashCode extends PackedArenaObject { export class HashCode extends PackedArenaObject {
@ -593,23 +607,7 @@ export class HashCode extends PackedArenaObject {
static fromCrock: (s: string) => HashCode; static fromCrock: (s: string) => HashCode;
random(qualStr: string) { random(qual: RandomQuality = RandomQuality.STRONG) {
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}`);
}
this.alloc(); this.alloc();
emsc.hash_create_random(qual, this.nativePtr); emsc.hash_create_random(qual, this.nativePtr);
} }
@ -955,7 +953,7 @@ mixin(RsaSignature, makeEncode(emscAlloc.rsa_signature_encode));
export function rsaBlind(hashCode: HashCode, export function rsaBlind(hashCode: HashCode,
blindingKey: RsaBlindingKey, blindingKey: RsaBlindingKeySecret,
pkey: RsaPublicKey, pkey: RsaPublicKey,
arena?: Arena): ByteArray { arena?: Arena): ByteArray {
let ptr = emscAlloc.malloc(PTR_SIZE); let ptr = emscAlloc.malloc(PTR_SIZE);
@ -997,7 +995,7 @@ export function eddsaVerify(purposeNum: number,
export function rsaUnblind(sig: RsaSignature, export function rsaUnblind(sig: RsaSignature,
bk: RsaBlindingKey, bk: RsaBlindingKeySecret,
pk: RsaPublicKey, pk: RsaPublicKey,
a?: Arena): RsaSignature { a?: Arena): RsaSignature {
let x = new RsaSignature(a); let x = new RsaSignature(a);