first
This commit is contained in:
30
node_modules/crypto-es/lib/pad-iso10126.js
generated
vendored
Normal file
30
node_modules/crypto-es/lib/pad-iso10126.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import {
|
||||
WordArray,
|
||||
} from './core.js';
|
||||
|
||||
/**
|
||||
* ISO 10126 padding strategy.
|
||||
*/
|
||||
export const Iso10126 = {
|
||||
pad(data, blockSize) {
|
||||
// Shortcut
|
||||
const blockSizeBytes = blockSize * 4;
|
||||
|
||||
// Count padding bytes
|
||||
const nPaddingBytes = blockSizeBytes - (data.sigBytes % blockSizeBytes);
|
||||
|
||||
// Pad
|
||||
data
|
||||
.concat(WordArray.random(nPaddingBytes - 1))
|
||||
.concat(WordArray.create([nPaddingBytes << 24], 1));
|
||||
},
|
||||
|
||||
unpad(data) {
|
||||
const _data = data;
|
||||
// Get number of padding bytes from last byte
|
||||
const nPaddingBytes = _data.words[(_data.sigBytes - 1) >>> 2] & 0xff;
|
||||
|
||||
// Remove padding
|
||||
_data.sigBytes -= nPaddingBytes;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user