Skip to content

Commit e5d5e7c

Browse files
committed
Adjust comments
1 parent c471485 commit e5d5e7c

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

‎src/_arx.ts

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const sigma32 = _utf8ToBytes('expand 32-byte k');
4949
const sigma16_32 = u32(sigma16);
5050
const sigma32_32 = u32(sigma32);
5151

52+
/** Rotate left. */
5253
export function rotl(a: number, b: number): number {
5354
return (a << b) | (a >>> (32 - b));
5455
}

‎src/_micro.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export const chacha20: XorStream = /* @__PURE__ */ createCipher(chachaCore, {
174174
counterLength: 4,
175175
});
176176

177-
/** xchacha20 eXtended-nonce. https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha */
177+
/** xchacha20 eXtended-nonce. See [IRTF draft](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha) */
178178
export const xchacha20: XorStream = /* @__PURE__ */ createCipher(chachaCore, {
179179
counterRight: false,
180180
counterLength: 8,

‎src/aes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ const limit = (name: string, min: number, max: number) => (value: number) => {
676676
* AES-GCM-SIV: classic AES-GCM with nonce-misuse resistance.
677677
* Guarantees that, when a nonce is repeated, the only security loss is that identical
678678
* plaintexts will produce identical ciphertexts.
679-
* RFC 8452, https://datatracker.ietf.org/doc/html/rfc8452
679+
* See [RFC 8452](https://datatracker.ietf.org/doc/html/rfc8452).
680680
*/
681681
export const gcmsiv: ((key: Uint8Array, nonce: Uint8Array, AAD?: Uint8Array) => Cipher) & {
682682
blockSize: number;

‎src/chacha.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export const chacha20: XorStream = /* @__PURE__ */ createCipher(chachaCore, {
175175
/**
176176
* XChaCha eXtended-nonce ChaCha. 24-byte nonce.
177177
* With 24-byte nonce, it's safe to use fill it with random (CSPRNG).
178-
* https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha
178+
* See [IRTF draft](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha).
179179
*/
180180
export const xchacha20: XorStream = /* @__PURE__ */ createCipher(chachaCore, {
181181
counterRight: false,
@@ -232,9 +232,7 @@ function computeTag(
232232
/**
233233
* AEAD algorithm from RFC 8439.
234234
* Salsa20 and chacha (RFC 8439) use poly1305 differently.
235-
* We could have composed them similar to:
236-
* https://github.com/paulmillr/scure-base/blob/b266c73dde977b1dd7ef40ef7a23cc15aab526b3/index.ts#L250
237-
* But it's hard because of authKey:
235+
* We could have composed them, but it's hard because of authKey:
238236
* In salsa20, authKey changes position in salsa stream.
239237
* In chacha, authKey can't be computed inside computeTag, it modifies the counter.
240238
*/

‎src/webcrypto.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
import { crypto } from '@noble/ciphers/crypto';
1313
import { abytes, anumber, type AsyncCipher, type Cipher, concatBytes } from './utils.ts';
1414

15+
function getWebcryptoSubtle(): any {
16+
if (crypto && typeof crypto.subtle === 'object' && crypto.subtle != null) return crypto.subtle;
17+
throw new Error('crypto.subtle must be defined');
18+
}
19+
1520
/**
1621
* Secure PRNG. Uses `crypto.getRandomValues`, which defers to OS.
1722
*/
@@ -26,11 +31,6 @@ export function randomBytes(bytesLength = 32): Uint8Array {
2631
throw new Error('crypto.getRandomValues must be defined');
2732
}
2833

29-
export function getWebcryptoSubtle(): any {
30-
if (crypto && typeof crypto.subtle === 'object' && crypto.subtle != null) return crypto.subtle;
31-
throw new Error('crypto.subtle must be defined');
32-
}
33-
3434
type RemoveNonceInner<T extends any[], Ret> = ((...args: T) => Ret) extends (
3535
arg0: any,
3636
arg1: any,
@@ -76,8 +76,10 @@ export function managedNonce<T extends CipherWithNonce>(fn: T): RemoveNonce<T> {
7676
})) as RemoveNonce<T>;
7777
}
7878

79-
// Overridable
80-
// @TODO
79+
/**
80+
* Internal webcrypto utils. Can be overridden of crypto.subtle is not present,
81+
* for example in React Native.
82+
*/
8183
export const utils: {
8284
encrypt: (key: Uint8Array, ...all: any[]) => Promise<Uint8Array>;
8385
decrypt: (key: Uint8Array, ...all: any[]) => Promise<Uint8Array>;

0 commit comments

Comments
 (0)