Namespace: bitArray

sjcl.bitArray

These objects are the currency accepted by SJCL's crypto functions.

Most of our crypto primitives operate on arrays of 4-byte words internally, but many of them can take arguments that are not a multiple of 4 bytes. This library encodes arrays of bits (whose size need not be a multiple of 8 bits) as arrays of 32-bit words. The bits are packed, big-endian, into an array of words, 32 bits at a time. Since the words are double-precision floating point numbers, they fit some extra data. We use this (in a private, possibly-changing manner) to encode the number of bits actually present in the last word of the array.

Because bitwise ops clear this out-of-band data, these arrays can be passed to ciphers like AES which want arrays of words.

Source:

Methods

(static) bitLength(a) → {Number}

Find the length of an array of bits.
Parameters:
Name Type Description
a bitArray The array.
Source:
Returns:
The length of a, in bits.
Type
Number

(static) bitSlice(a, bstart, bend) → {bitArray}

Array slices in units of bits.
Parameters:
Name Type Description
a bitArray The array to slice.
bstart Number The offset to the start of the slice, in bits.
bend Number The offset to the end of the slice, in bits. If this is undefined, slice until the end of the array.
Source:
Returns:
The requested slice.
Type
bitArray

(static) byteswapM(a) → {sjcl.bitArray}

byteswap a word array inplace. (does not handle partial words)
Parameters:
Name Type Description
a sjcl.bitArray word array
Source:
Returns:
byteswapped array
Type
sjcl.bitArray

(static) clamp(a, len) → {bitArray}

Truncate an array.
Parameters:
Name Type Description
a bitArray The array.
len Number The length to truncate to, in bits.
Source:
Returns:
A new array, truncated to len bits.
Type
bitArray

(static) concat(a1, a2) → {bitArray}

Concatenate two bit arrays.
Parameters:
Name Type Description
a1 bitArray The first array.
a2 bitArray The second array.
Source:
Returns:
The concatenation of a1 and a2.
Type
bitArray

(static) equal(a, b) → {boolean}

Compare two arrays for equality in a predictable amount of time.
Parameters:
Name Type Description
a bitArray The first array.
b bitArray The second array.
Source:
Returns:
true if a == b; false otherwise.
Type
boolean

(static) extract(a, bstart, blength) → {Number}

Extract a number packed into a bit array.
Parameters:
Name Type Description
a bitArray The array to slice.
bstart Number The offset to the start of the slice, in bits.
blength Number The length of the number to extract.
Source:
Returns:
The requested slice.
Type
Number

(static) getPartial(x) → {Number}

Get the number of bits used by a partial word.
Parameters:
Name Type Description
x Number The partial word.
Source:
Returns:
The number of bits used by the partial word.
Type
Number

(static) partial(len, x, _endopt) → {Number}

Make a partial word for a bit array.
Parameters:
Name Type Attributes Default Description
len Number The number of bits in the word.
x Number The bits.
_end Number <optional>
0 Pass 1 if x has already been shifted to the high side.
Source:
Returns:
The partial word.
Type
Number