Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directly return platform signature for blindrsa #30

Merged
merged 1 commit into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions src/blindrsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
i2osp,
is_coprime,
joinAll,
NATIVE_SUPPORT_NAME,
os2ip,
random_integer_uniform,
rsaRawBlingSign,
Expand Down Expand Up @@ -71,14 +70,7 @@ export class BlindRSA {
modulusLengthBytes: number;
hash: string;
}> {
if (key.type !== type) {
throw new Error(`key is not ${type}`);
}
const algorithmNames = [BlindRSA.NAME];
if (this.params.supportsRSARAW) {
algorithmNames.push(NATIVE_SUPPORT_NAME);
}
if (!algorithmNames.includes(key.algorithm.name)) {
if (key.type !== type || key.algorithm.name !== BlindRSA.NAME) {
throw new Error(`key is not ${BlindRSA.NAME}`);
}
if (!key.extractable) {
Expand Down Expand Up @@ -155,6 +147,9 @@ export class BlindRSA {
}

async blindSign(privateKey: CryptoKey, blindMsg: Uint8Array): Promise<Uint8Array> {
if (this.params.supportsRSARAW) {
return rsaRawBlingSign(privateKey, blindMsg);
}
const { jwkKey, modulusLengthBytes: kLen } = await this.extractKeyParams(
privateKey,
'private',
Expand All @@ -172,12 +167,7 @@ export class BlindRSA {
const m = os2ip(blindMsg);

// 2. s = RSASP1(sk, m)
let s: sjcl.BigNumber;
if (this.params.supportsRSARAW) {
s = await rsaRawBlingSign(privateKey, blindMsg);
} else {
s = rsasp1(sk, m);
}
const s = rsasp1(sk, m);

// 3. m' = RSAVP1(pk, s)
const mp = rsavp1(pk, s);
Expand Down
12 changes: 2 additions & 10 deletions src/partially_blindrsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
rsavp1,
inverseMod,
rsaRawBlingSign,
NATIVE_SUPPORT_NAME,
prepare_sjcl_random_generator,
type BigPublicKey,
type BigSecretKey,
Expand Down Expand Up @@ -68,14 +67,7 @@ export class PartiallyBlindRSA {
modulusLengthBytes: number;
hash: string;
}> {
if (key.type !== type) {
throw new Error(`key is not ${type}`);
}
const algorithmNames = [PartiallyBlindRSA.NAME];
if (this.params.supportsRSARAW) {
algorithmNames.push(NATIVE_SUPPORT_NAME);
}
if (!algorithmNames.includes(key.algorithm.name)) {
if (key.type !== type || key.algorithm.name !== PartiallyBlindRSA.NAME) {
throw new Error(`key is not ${PartiallyBlindRSA.NAME}`);
}
if (!key.extractable) {
Expand Down Expand Up @@ -197,7 +189,7 @@ export class PartiallyBlindRSA {
},
true,
);
s = await rsaRawBlingSign(privateKey, blindMsg);
s = os2ip(await rsaRawBlingSign(privateKey, blindMsg));
} else {
s = rsasp1(sk_derived, m);
}
Expand Down
4 changes: 2 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export const NATIVE_SUPPORT_NAME = 'RSA-RAW';
export async function rsaRawBlingSign(
privateKey: CryptoKey,
blindMsg: Uint8Array,
): Promise<sjcl.BigNumber> {
): Promise<Uint8Array> {
if (privateKey.algorithm.name !== NATIVE_SUPPORT_NAME) {
privateKey = await crypto.subtle.importKey(
'pkcs8',
Expand All @@ -333,7 +333,7 @@ export async function rsaRawBlingSign(
privateKey,
blindMsg,
);
return os2ip(new Uint8Array(signature));
return new Uint8Array(signature);
}

export type BigPublicKey = { e: sjcl.BigNumber; n: sjcl.BigNumber };
Expand Down