packages/cafeteria/plugins/cordova-plugin-secure-storage/www/sjcl_ss.js
function(prf, data, iv, tag, tlen, L) {
    var enc, i, w=sjcl.bitArray, xor = w._xor4, ctr, l = data.length, bl=w.bitLength(data);

    // start the ctr
    ctr = w.concat([w.partial(8,L-1)],iv).concat([0,0,0]).slice(0,4);

    // en/decrypt the tag
    tag = w.bitSlice(xor(tag,prf.encrypt(ctr)), 0, tlen);

    // en/decrypt the data
    if (!l) { return {tag:tag, data:[]}; }

    for (i=0; i<l; i+=4) {
      ctr[3]++;
      enc = prf.encrypt(ctr);
      data[i]   ^= enc[0];
      data[i+1] ^= enc[1];
      data[i+2] ^= enc[2];
      data[i+3] ^= enc[3];
    }
    return { tag:tag, data:w.clamp(data,bl) };
  }
function(prf, data, iv, tag, tlen, L) {
    var enc, i, w=sjcl.bitArray, xor = w._xor4, ctr, l = data.length, bl=w.bitLength(data);

    // start the ctr
    ctr = w.concat([w.partial(8,L-1)],iv).concat([0,0,0]).slice(0,4);

    // en/decrypt the tag
    tag = w.bitSlice(xor(tag,prf.encrypt(ctr)), 0, tlen);

    // en/decrypt the data
    if (!l) { return {tag:tag, data:[]}; }

    for (i=0; i<l; i+=4) {
      ctr[3]++;
      enc = prf.encrypt(ctr);
      data[i]   ^= enc[0];
      data[i+1] ^= enc[1];
      data[i+2] ^= enc[2];
      data[i+3] ^= enc[3];
    }
    return { tag:tag, data:w.clamp(data,bl) };
  }
function ( prf , data , iv , tag , tlen , L ) { var enc , i , w = sjcl . bitArray , xor = w . _xor4 , ctr , l = data . length , bl = w . bitLength ( data ) ; // start the ctr ctr = w . concat ( [ w . partial ( 8 , L - 1 ) ] , iv ) . concat ( [ 0 , 0 , 0 ] ) . slice ( 0 , 4 ) ; // en/decrypt the tag tag = w . bitSlice ( xor ( tag , prf . encrypt ( ctr ) ) , 0 , tlen ) ; // en/decrypt the data if ( ! l ) { return { tag : tag , data : [ ] } ; } for ( i = 0 ; i < l ; i += 4 ) { ctr [ 3 ] ++ ; enc = prf . encrypt ( ctr ) ; data [ i ] ^= enc [ 0 ] ; data [ i + 1 ] ^= enc [ 1 ] ; data [ i + 2 ] ^= enc [ 2 ] ; data [ i + 3 ] ^= enc [ 3 ] ; } return { tag : tag , data : w . clamp ( data , bl ) } ; }
CCM CTR mode.
Encrypt or decrypt data and tag with the prf in CCM-style CTR mode.
May mutate its arguments.
@param {Object} prf The PRF.
@param {bitArray} data The data to be encrypted or decrypted.
@param {bitArray} iv The initialization vector.
@param {bitArray} tag The authentication tag.
@param {Number} tlen The length of th etag, in bits.
@param {Number} L The CCM L value.
@return {Object} An object with data and tag, the en/decryption of data and tag values.
@private
CCM CTR mode . Encrypt or decrypt data and tag with the prf in CCM - style CTR mode . May mutate its arguments .