GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — crypto: minimize RSA public exponent metadata · nodejs/node@2ac8c82

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/crypto
    • rsa.js
  • test/parallel
    • test-webcrypto-rsa-exponent-length.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/crypto/rsa.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/rsa.js
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
const {
44
TypedArrayPrototypeGetBuffer,
5+
TypedArrayPrototypeGetByteOffset,
6+
TypedArrayPrototypeGetLength,
57
Uint8Array,
68
} = primordials;
79

@@ -111,11 +113,17 @@ function rsaKeyGenerate(
111113
const allowedUsages = kUsages[name];
112114
const usagesSet = validateKeyUsages(usages, allowedUsages.keygen, name);
113115
const publicExponentConverted = bigIntArrayToUnsignedInt(publicExponent);
116+
let firstNonzeroByte = 0;
117+
while (publicExponent[firstNonzeroByte] === 0)
118+
firstNonzeroByte++;
114119

115120
const keyAlgorithm = {
116121
name,
117122
modulusLength,
118-
publicExponent,
123+
publicExponent: new Uint8Array(
124+
TypedArrayPrototypeGetBuffer(publicExponent),
125+
TypedArrayPrototypeGetByteOffset(publicExponent) + firstNonzeroByte,
126+
TypedArrayPrototypeGetLength(publicExponent) - firstNonzeroByte),
119127
hash,
120128
};
121129

Collapse file

‎test/parallel/test-webcrypto-rsa-exponent-length.js‎

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
const assert = require('assert');
8+
const { getFips } = require('crypto');
9+
const { subtle } = globalThis.crypto;
10+
11+
(async () => {
12+
const exponents = getFips() ? [[1, 0, 1]] : [[3], [1, 0, 1]];
13+
for (const name of ['RSA-PSS', 'RSASSA-PKCS1-v1_5', 'RSA-OAEP']) {
14+
const usages = name === 'RSA-OAEP' ? ['encrypt', 'decrypt'] : ['sign', 'verify'];
15+
for (const exponent of exponents) {
16+
const publicExponent = new Uint8Array([0, 0, 0, 0, ...exponent]);
17+
const pair = await subtle.generateKey({
18+
name, modulusLength: 2048, publicExponent, hash: 'SHA-256',
19+
}, true, usages);
20+
for (const key of [pair.publicKey, pair.privateKey]) {
21+
assert.deepStrictEqual(key.algorithm.publicExponent, new Uint8Array(exponent));
22+
}
23+
assert.deepStrictEqual(publicExponent, new Uint8Array([0, 0, 0, 0, ...exponent]));
24+
}
25+
}
26+
})().then(common.mustCall());

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.