From 37215d7a3cee7f14683817699c0ef4f5383dfbd0 Mon Sep 17 00:00:00 2001 From: morrigan Date: Mon, 4 Nov 2019 14:38:01 +0100 Subject: [PATCH] use function visibility --- src/xx.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/xx.ts b/src/xx.ts index 17646c8..7ff520f 100644 --- a/src/xx.ts +++ b/src/xx.ts @@ -51,7 +51,7 @@ class XXHandshake { return {ss, s, e, rs, re, psk}; } - async initializeResponder(prologue: bytes32, s: KeyPair, rs: bytes32, psk: bytes32) : Promise { + private async initializeResponder(prologue: bytes32, s: KeyPair, rs: bytes32, psk: bytes32) : Promise { const e: KeyPair; const re: bytes32; const name = "Noise_XX_25519_ChaChaPoly_SHA256"; @@ -61,11 +61,11 @@ class XXHandshake { return {ss, s, e, rs, re, psk}; } - incrementNonce(n: uint32) : uint32 { + private incrementNonce(n: uint32) : uint32 { return n + 1; } - encrypt(k: bytes32, n: uint32, ad: bytes, plaintext: bytes) : bytes { + private encrypt(k: bytes32, n: uint32, ad: bytes, plaintext: bytes) : bytes { const nonce = Buffer.alloc(12); nonce.writeUInt32LE(n, 4); const ctx = new AEAD(); @@ -77,16 +77,16 @@ class XXHandshake { } // Cipher state related - initializeKey(k: bytes32) : CipherState { + private initializeKey(k: bytes32) : CipherState { const n = minNonce; return { k, n }; } - setNonce(cs: CipherState, nonce: uint32) { + private setNonce(cs: CipherState, nonce: uint32) { cs.n = nonce; } - encryptWithAd(cs: CipherState, ad: bytes, plaintext: bytes) : bytes { + private encryptWithAd(cs: CipherState, ad: bytes, plaintext: bytes) : bytes { const e = this.encrypt(cs.k, cs.n, ad, plaintext); this.setNonce(cs, this.incrementNonce(cs.n)); return e; @@ -94,7 +94,7 @@ class XXHandshake { // Symmetric state related - async initializeSymmetric(protocolName: string) : Promise { + private async initializeSymmetric(protocolName: string) : Promise { const h = await this.hashProtocolName(protocolName); const ck = h; const cs = this.initializeKey(emptyKey); @@ -102,27 +102,27 @@ class XXHandshake { return { cs, ck, h }; } - async hashProtocolName(protocolName: string) : Promise { + private async hashProtocolName(protocolName: string) : Promise { if (protocolName.length <= 32) { return new Promise(resolve => { - const h = new Buffer(32); + const h = Buffer.alloc(32); h.write(protocolName); resolve(h) }); } else { - return await this.getHash(Buffer.from(protocolName), new Buffer([])); + return await this.getHash(Buffer.from(protocolName, 'utf-8'), Buffer.from([])); } } - async mixHash(ss: SymmetricState, data: bytes) { + private async mixHash(ss: SymmetricState, data: bytes) { ss.h = await this.getHash(ss.h, data); } - async getHash(a: bytes, b: bytes) : Promise { + private async getHash(a: bytes, b: bytes) : Promise { return await crypto.hmac.create('sha256', Buffer.from([...a, ...b])) } - async initSession(initiator: boolean, prologue: bytes32[], s: KeyPair, rs: bytes32) : Promise { + public async initSession(initiator: boolean, prologue: bytes32[], s: KeyPair, rs: bytes32) : Promise { let session: NoiseSession; const psk = emptyKey;