Skip to content

Commit 5bc71ae

Browse files
committed
conflict solved
1 parent 3a4da18 commit 5bc71ae

File tree

190 files changed

+64963
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+64963
-5
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Build Windows
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- README.md
7+
- .github/**
8+
- '!.github/workflows/build-windows.yml'
9+
types: [opened, synchronize, reopened, ready_for_review]
10+
push:
11+
branches:
12+
- main
13+
- canary
14+
- v[0-9]+.x-staging
15+
- v[0-9]+.x
16+
paths-ignore:
17+
- README.md
18+
- .github/**
19+
- '!.github/workflows/build-windows.yml'
20+
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
23+
cancel-in-progress: true
24+
25+
env:
26+
PYTHON_VERSION: '3.11'
27+
FLAKY_TESTS: keep_retrying
28+
29+
permissions:
30+
contents: read
31+
32+
jobs:
33+
build-windows:
34+
if: github.event.pull_request.draft == false
35+
strategy:
36+
matrix:
37+
windows: [windows-2019, windows-2022]
38+
fail-fast: false
39+
runs-on: ${{ matrix.windows }}
40+
steps:
41+
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
42+
with:
43+
persist-credentials: false
44+
- name: Set up Python ${{ env.PYTHON_VERSION }}
45+
uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 # v4.5.0
46+
with:
47+
python-version: ${{ env.PYTHON_VERSION }}
48+
- name: Install deps
49+
run: choco install nasm
50+
- name: Environment Information
51+
run: npx envinfo
52+
- name: Build
53+
run: ./vcbuild.bat

.github/workflows/test-asan.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Test ASan
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
paths-ignore:
7+
- .mailmap
8+
- '**.md'
9+
- AUTHORS
10+
- doc/**
11+
- .github/**
12+
- '!.github/workflows/test-asan.yml'
13+
push:
14+
branches:
15+
- main
16+
- canary
17+
- v[0-9]+.x-staging
18+
- v[0-9]+.x
19+
paths-ignore:
20+
- .mailmap
21+
- '**.md'
22+
- AUTHORS
23+
- doc/**
24+
- .github/**
25+
- '!.github/workflows/test-asan.yml'
26+
27+
concurrency:
28+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
29+
cancel-in-progress: true
30+
31+
env:
32+
ASAN_OPTIONS: intercept_tls_get_addr=0
33+
PYTHON_VERSION: '3.11'
34+
FLAKY_TESTS: keep_retrying
35+
36+
permissions:
37+
contents: read
38+
39+
jobs:
40+
test-asan:
41+
if: github.event.pull_request.draft == false
42+
runs-on: ubuntu-20.04
43+
env:
44+
CC: clang
45+
CXX: clang++
46+
LINK: clang++
47+
CONFIG_FLAGS: --enable-asan
48+
ASAN: true
49+
steps:
50+
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
51+
with:
52+
persist-credentials: false
53+
- name: Set up Python ${{ env.PYTHON_VERSION }}
54+
uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 # v4.5.0
55+
with:
56+
python-version: ${{ env.PYTHON_VERSION }}
57+
- name: Environment Information
58+
run: npx envinfo
59+
- name: Build
60+
run: make build-ci -j2 V=1
61+
- name: Test
62+
run: make run-ci -j2 V=1 TEST_CI_ARGS="-p actions -t 300 --measure-flakiness 9"

benchmark/buffers/buffer-hex.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
5+
const bench = common.createBenchmark(main, {
6+
len: [64, 1024],
7+
n: [1e6],
8+
});
9+
10+
function main({ len, n }) {
11+
const buf = Buffer.alloc(len);
12+
13+
for (let i = 0; i < buf.length; i++)
14+
buf[i] = i & 0xff;
15+
16+
const hex = buf.toString('hex');
17+
18+
bench.start();
19+
20+
for (let i = 0; i < n; i += 1)
21+
Buffer.from(hex, 'hex');
22+
23+
bench.end(n);
24+
}

benchmark/crypto/cipher-stream.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
4+
const bench = common.createBenchmark(main, {
5+
writes: [500],
6+
cipher: ['AES192', 'AES256'],
7+
type: ['asc', 'utf', 'buf'],
8+
len: [2, 1024, 102400, 1024 * 1024],
9+
api: ['legacy', 'stream'],
10+
}, {
11+
flags: ['--no-warnings'],
12+
});
13+
14+
function main({ api, cipher, type, len, writes }) {
15+
if (api === 'stream' && /^v0\.[0-8]\./.test(process.version)) {
16+
console.error('Crypto streams not available until v0.10');
17+
// Use the legacy, just so that we can compare them.
18+
api = 'legacy';
19+
}
20+
21+
const crypto = require('crypto');
22+
const assert = require('assert');
23+
const alice = crypto.getDiffieHellman('modp5');
24+
const bob = crypto.getDiffieHellman('modp5');
25+
26+
alice.generateKeys();
27+
bob.generateKeys();
28+
29+
const pubEnc = /^v0\.[0-8]/.test(process.version) ? 'binary' : null;
30+
const alice_secret = alice.computeSecret(bob.getPublicKey(), pubEnc, 'hex');
31+
const bob_secret = bob.computeSecret(alice.getPublicKey(), pubEnc, 'hex');
32+
33+
// alice_secret and bob_secret should be the same
34+
assert(alice_secret === bob_secret);
35+
36+
const alice_cipher = crypto.createCipher(cipher, alice_secret);
37+
const bob_cipher = crypto.createDecipher(cipher, bob_secret);
38+
39+
let message;
40+
let encoding;
41+
switch (type) {
42+
case 'asc':
43+
message = 'a'.repeat(len);
44+
encoding = 'ascii';
45+
break;
46+
case 'utf':
47+
message = 'ü'.repeat(len / 2);
48+
encoding = 'utf8';
49+
break;
50+
case 'buf':
51+
message = Buffer.alloc(len, 'b');
52+
break;
53+
default:
54+
throw new Error(`unknown message type: ${type}`);
55+
}
56+
57+
const fn = api === 'stream' ? streamWrite : legacyWrite;
58+
59+
// Write data as fast as possible to alice, and have bob decrypt.
60+
// use old API for comparison to v0.8
61+
bench.start();
62+
fn(alice_cipher, bob_cipher, message, encoding, writes);
63+
}
64+
65+
function streamWrite(alice, bob, message, encoding, writes) {
66+
let written = 0;
67+
bob.on('data', (c) => {
68+
written += c.length;
69+
});
70+
71+
bob.on('end', () => {
72+
// Gbits
73+
const bits = written * 8;
74+
const gbits = bits / (1024 * 1024 * 1024);
75+
bench.end(gbits);
76+
});
77+
78+
alice.pipe(bob);
79+
80+
while (writes-- > 0)
81+
alice.write(message, encoding);
82+
83+
alice.end();
84+
}
85+
86+
function legacyWrite(alice, bob, message, encoding, writes) {
87+
let written = 0;
88+
let enc, dec;
89+
for (let i = 0; i < writes; i++) {
90+
enc = alice.update(message, encoding);
91+
dec = bob.update(enc);
92+
written += dec.length;
93+
}
94+
enc = alice.final();
95+
dec = bob.update(enc);
96+
written += dec.length;
97+
dec = bob.final();
98+
written += dec.length;
99+
const gbits = written / (1024 * 1024 * 1024);
100+
bench.end(gbits);
101+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const crypto = require('crypto');
5+
const fs = require('fs');
6+
const path = require('path');
7+
const fixtures_keydir = path.resolve(__dirname, '../../test/fixtures/keys/');
8+
const keyFixtures = {
9+
publicKey: fs.readFileSync(`${fixtures_keydir}/ec_p256_public.pem`)
10+
.toString(),
11+
privateKey: fs.readFileSync(`${fixtures_keydir}/ec_p256_private.pem`)
12+
.toString(),
13+
};
14+
15+
const data = crypto.randomBytes(256);
16+
17+
let pems;
18+
let keyObjects;
19+
20+
function getKeyObject({ privateKey, publicKey }) {
21+
return {
22+
privateKey: crypto.createPrivateKey(privateKey),
23+
publicKey: crypto.createPublicKey(publicKey),
24+
};
25+
}
26+
27+
const bench = common.createBenchmark(main, {
28+
mode: ['sync', 'async-serial', 'async-parallel'],
29+
keyFormat: ['pem', 'keyObject', 'pem.unique', 'keyObject.unique'],
30+
n: [1e3],
31+
});
32+
33+
function measureSync(n, privateKey, publicKey, keys) {
34+
bench.start();
35+
for (let i = 0; i < n; ++i) {
36+
crypto.verify(
37+
'sha256',
38+
data,
39+
{ key: publicKey || keys[i].publicKey, dsaEncoding: 'ieee-p1363' },
40+
crypto.sign(
41+
'sha256',
42+
data,
43+
{ key: privateKey || keys[i].privateKey, dsaEncoding: 'ieee-p1363' }));
44+
}
45+
bench.end(n);
46+
}
47+
48+
function measureAsyncSerial(n, privateKey, publicKey, keys) {
49+
let remaining = n;
50+
function done() {
51+
if (--remaining === 0)
52+
bench.end(n);
53+
else
54+
one();
55+
}
56+
57+
function one() {
58+
crypto.sign(
59+
'sha256',
60+
data,
61+
{
62+
key: privateKey || keys[n - remaining].privateKey,
63+
dsaEncoding: 'ieee-p1363',
64+
},
65+
(err, signature) => {
66+
crypto.verify(
67+
'sha256',
68+
data,
69+
{
70+
key: publicKey || keys[n - remaining].publicKey,
71+
dsaEncoding: 'ieee-p1363',
72+
},
73+
signature,
74+
done);
75+
});
76+
}
77+
bench.start();
78+
one();
79+
}
80+
81+
function measureAsyncParallel(n, privateKey, publicKey, keys) {
82+
let remaining = n;
83+
function done() {
84+
if (--remaining === 0)
85+
bench.end(n);
86+
}
87+
bench.start();
88+
for (let i = 0; i < n; ++i) {
89+
crypto.sign(
90+
'sha256',
91+
data,
92+
{ key: privateKey || keys[i].privateKey, dsaEncoding: 'ieee-p1363' },
93+
(err, signature) => {
94+
crypto.verify(
95+
'sha256',
96+
data,
97+
{ key: publicKey || keys[i].publicKey, dsaEncoding: 'ieee-p1363' },
98+
signature,
99+
done);
100+
});
101+
}
102+
}
103+
104+
function main({ n, mode, keyFormat }) {
105+
pems ||= [...Buffer.alloc(n)].map(() => ({
106+
privateKey: keyFixtures.privateKey,
107+
publicKey: keyFixtures.publicKey,
108+
}));
109+
keyObjects ||= pems.map(getKeyObject);
110+
111+
let privateKey, publicKey, keys;
112+
113+
switch (keyFormat) {
114+
case 'keyObject':
115+
({ publicKey, privateKey } = keyObjects[0]);
116+
break;
117+
case 'pem':
118+
({ publicKey, privateKey } = pems[0]);
119+
break;
120+
case 'pem.unique':
121+
keys = pems;
122+
break;
123+
case 'keyObject.unique':
124+
keys = keyObjects;
125+
break;
126+
default:
127+
throw new Error('not implemented');
128+
}
129+
130+
switch (mode) {
131+
case 'sync':
132+
measureSync(n, privateKey, publicKey, keys);
133+
break;
134+
case 'async-serial':
135+
measureAsyncSerial(n, privateKey, publicKey, keys);
136+
break;
137+
case 'async-parallel':
138+
measureAsyncParallel(n, privateKey, publicKey, keys);
139+
break;
140+
}
141+
}

0 commit comments

Comments
 (0)