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 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()
}

View File

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

View File

@ -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);
export class RsaBlindingKeySecret extends PackedArenaObject {
size() {
return 32;
}
/**
* Create a random blinding key secret.
*/
static create(a?: Arena): RsaBlindingKeySecret {
let o = new RsaBlindingKeySecret(a);
o.alloc();
o.randomize();
return o;
}
static fromCrock: (s: string, a?: Arena) => RsaBlindingKey;
toCrock = makeToCrock(emscAlloc.rsa_blinding_key_encode);
destroy() {
// TODO
}
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);