( conversationKey: Buffer, nonce: Buffer, )
| 42 | } |
| 43 | |
| 44 | function getMessageKeys( |
| 45 | conversationKey: Buffer, |
| 46 | nonce: Buffer, |
| 47 | ): { chachaKey: Buffer; chachaNonce: Buffer; hmacKey: Buffer } { |
| 48 | if (conversationKey.length !== 32) { |
| 49 | throw new Error('invalid conversation_key length') |
| 50 | } |
| 51 | if (nonce.length !== 32) { |
| 52 | throw new Error('invalid nonce length') |
| 53 | } |
| 54 | |
| 55 | const keys = hkdfExpand(conversationKey, nonce, 76) |
| 56 | return { |
| 57 | chachaKey: keys.subarray(0, 32), |
| 58 | chachaNonce: keys.subarray(32, 44), |
| 59 | hmacKey: keys.subarray(44, 76), |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | function calcPaddedLen(unpaddedLen: number): number { |
| 64 | if (unpaddedLen <= 32) { |
no test coverage detected