Skip to content

Commit

Permalink
arx: Remove hard-dependency on TextEncoder
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Apr 23, 2024
1 parent 3359d96 commit e1046f5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/_arx.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Basic utils for ARX (add-rotate-xor) salsa and chacha ciphers.
import { number as anumber, bytes as abytes, bool as abool } from './_assert.js';
import { XorStream, checkOpts, u32, utf8ToBytes } from './utils.js';
import { XorStream, checkOpts, u32 } from './utils.js';

/*
RFC8439 requires multi-step cipher stream, where
Expand Down Expand Up @@ -37,8 +37,11 @@ xchacha [^2] uses the subkey and remaining 8 byte nonce with ChaCha20 as normal
[^2]: https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha#appendix-A.2
*/

const sigma16 = utf8ToBytes('expand 16-byte k');
const sigma32 = utf8ToBytes('expand 32-byte k');
// We can't make top-level var depend on utils.utf8ToBytes
// because it's not present in all envs. Creating a similar fn here
const _utf8ToBytes = (str: string) => Uint8Array.from(str.split('').map((c) => c.charCodeAt(0)));
const sigma16 = _utf8ToBytes('expand 16-byte k');
const sigma32 = _utf8ToBytes('expand 32-byte k');
const sigma16_32 = u32(sigma16);
const sigma32_32 = u32(sigma32);

Expand Down

0 comments on commit e1046f5

Please sign in to comment.