salty-crypto 0.0.5 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/profiles.ts DELETED
@@ -1,59 +0,0 @@
1
- /// SPDX-License-Identifier: MIT
2
- /// SPDX-FileCopyrightText: Copyright © 2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
3
-
4
- import { BLAKE2s } from './blake2';
5
- import { AEAD_CHACHA20_POLY1305_NONCEBYTES, AEAD_CHACHA20_POLY1305_TAGBYTES, aead_decrypt, aead_encrypt } from './aead';
6
- import { DHKeyPair, NoiseProtocolAlgorithms, Nonce } from './noise';
7
- import { randomBytes } from './random';
8
- import { scalarMult, scalarMultBase } from './x25519';
9
-
10
- export class Noise_25519_ChaChaPoly_BLAKE2s extends NoiseProtocolAlgorithms {
11
- constructor () {
12
- super();
13
- }
14
-
15
- dhName(): string {
16
- return '25519';
17
- }
18
-
19
- generateKeypair(): DHKeyPair {
20
- const sk = randomBytes(scalarMult.scalarLength);
21
- const pk = scalarMultBase(sk);
22
- return { public: pk, secret: sk };
23
- }
24
-
25
- dh(kp: DHKeyPair, pk: Uint8Array): Uint8Array {
26
- return scalarMult(kp.secret, pk);
27
- }
28
-
29
- cipherName(): string {
30
- return 'ChaChaPoly';
31
- }
32
-
33
- encrypt(key: DataView, nonce: Nonce, p: Uint8Array, associated_data?: Uint8Array): Uint8Array {
34
- return aead_encrypt(p, key, serializeNonce(nonce), associated_data);
35
- }
36
-
37
- decrypt(key: DataView, nonce: Nonce, c: Uint8Array, associated_data?: Uint8Array): Uint8Array {
38
- return aead_decrypt(c, key, serializeNonce(nonce), associated_data);
39
- }
40
-
41
- hashName(): string {
42
- return "BLAKE2s";
43
- }
44
-
45
- hash(data: Uint8Array): Uint8Array {
46
- return BLAKE2s.digest(data);
47
- }
48
-
49
- hashBlocklen(): number {
50
- return BLAKE2s.BLOCKLEN;
51
- }
52
- }
53
-
54
- function serializeNonce(n: Nonce): DataView {
55
- const view = new DataView(new ArrayBuffer(AEAD_CHACHA20_POLY1305_NONCEBYTES));
56
- view.setUint32(4, n.lo, true);
57
- view.setUint32(8, n.hi, true);
58
- return view;
59
- }