1.1.3 • Published 3 years ago

@particle/device-control-crypto v1.1.3

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
3 years ago

@particle/device-control-crypto

Elliptic Curve J-PAKE and AES CCM for Node.js and browsers.

Installation

npm install @particle/device-control-crypto --save

API

Ccm

A class implementing the CCM mode of operation for a block cipher.

Kind: global class


new Ccm(options)

Constructor.

ParamTypeDefaultDescription
optionsObjectOptions.
options.encryptEncryptFunctionEncryption function.
options.nonceLengthNumberNonce length in bytes. The value must be in the range 7, 13.
options.tagLengthNumber16Length of the authentication tag in bytes: 4, 6, 8, 10, 12, 14 or 16.

ccm.encrypt(data, nonce, addData) ⇒ Promise.<Uint8Array>

Encrypt a message.

Kind: instance method of Ccm
Returns: Promise.<Uint8Array> - Encrypted data. The authentication tag is appended to the encrypted data.

ParamTypeDescription
dataUint8ArrayData to encrypt.
nonceUint8ArrayNonce.
addDataUint8ArrayAdditional authenticated data.

ccm.decrypt(data, nonce, addData) ⇒ Promise.<Uint8Array>

Decrypt a message.

Kind: instance method of Ccm
Returns: Promise.<Uint8Array> - Decrypted data.
Throws:

  • Throws an error if decryption fails.
ParamTypeDescription
dataUint8ArrayData to decrypt. The authentication tag must be appended to the encrypted data.
nonceUint8ArrayNonce.
addDataUint8ArrayAdditional authenticated data.

EcJpake

A class implementing the EC J-PAKE protocol as defined by the Thread specification.

Kind: global class


ecJpake.getRound1() ⇒ Promise.<Uint8Array>

Generate a message for the first round of the protocol.

Kind: instance method of EcJpake
Returns: Promise.<Uint8Array> - Message data.


ecJpake.readRound1(buf) ⇒ Number

Read a message generated by the peer for the first round of the protocol.

Kind: instance method of EcJpake
Returns: Number - Number of bytes read.

ParamTypeDescription
bufUint8ArrayMessage data.

ecJpake.getRound2() ⇒ Promise.<Uint8Array>

Generate a message for the second round of the protocol.

Kind: instance method of EcJpake
Returns: Promise.<Uint8Array> - Message data.


ecJpake.readRound2(buf) ⇒ Number

Read a message generated by the peer for the second round of the protocol.

Kind: instance method of EcJpake
Returns: Number - Number of bytes read.

ParamTypeDescription
bufUint8ArrayMessage data.

ecJpake.deriveSecret() ⇒ Promise.<Uint8Array>

Derive the shared secret.

Kind: instance method of EcJpake
Returns: Promise.<Uint8Array> - Shared secret.


createAes128Cipher(key) ⇒ EncryptFunction

Create an AES-128 cipher operating in ECB mode.

Kind: global function
Returns: EncryptFunction - Encryption function.

ParamTypeDescription
keyUint8ArrayEncryption key. The key must be 16 bytes long.

getRandomBytes(size) ⇒ Promise.<Uint8Array>

Generate cryptographically strong random data.

Kind: global function
Returns: Promise.<Uint8Array> - Random data.

ParamTypeDescription
sizeNumberNumber of bytes to generate.

EncryptFunction ⇒ Promise.<Uint8Array>

Encrypt a single block of data.

Kind: global typedef
Returns: Promise.<Uint8Array> - Ciphertext block.

ParamTypeDescription
blockUint8ArrayPlaintext block. The block must be 16 bytes long.

RandomFunction ⇒ Promise.<Uint8Array>

Constructor.

Kind: global typedef
Returns: Promise.<Uint8Array> - Random bytes.

ParamTypeDefaultDescription
sizeNumberNumber of random bytes to generate.
optionsObjectOptions.
options.roleStringRole of this peer: client or server.
options.secretString | Uint8ArrayPre-shared secret.
options.randomBytesRandomFunctiongetRandomBytesCryptographically strong random generator function.
options.curveStringp256Curve name.
options.clientIdString | Uint8ArrayclientClient identity.
options.serverIdString | Uint8ArrayserverServer identity.

NOTE: Unfortunately, docs have a nasty habit of falling out of date. When in doubt, check usage in tests