MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / Pad

Method Pad

extra/yassl/taocrypt/src/rsa.cpp:82–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80
81
82void RSA_BlockType2::Pad(const byte *input, word32 inputLen, byte *pkcsBlock,
83 word32 pkcsBlockLen, RandomNumberGenerator& rng) const
84{
85 // convert from bit length to byte length
86 if (pkcsBlockLen % 8 != 0)
87 {
88 pkcsBlock[0] = 0;
89 pkcsBlock++;
90 }
91 pkcsBlockLen /= 8;
92
93 pkcsBlock[0] = 2; // block type 2
94
95 // pad with non-zero random bytes
96 word32 padLen = pkcsBlockLen - inputLen - 1;
97 rng.GenerateBlock(&pkcsBlock[1], padLen);
98 for (word32 i = 1; i < padLen; i++)
99 if (pkcsBlock[i] == 0) pkcsBlock[i] = 0x01;
100
101 pkcsBlock[pkcsBlockLen-inputLen-1] = 0; // separator
102 memcpy(pkcsBlock+pkcsBlockLen-inputLen, input, inputLen);
103}
104
105word32 RSA_BlockType2::UnPad(const byte *pkcsBlock, unsigned int pkcsBlockLen,
106 byte *output) const

Callers 1

EncryptMethod · 0.80

Calls 1

GenerateBlockMethod · 0.80

Tested by

no test coverage detected