Created
March 8, 2011 21:04
-
-
Save zbroyar/861054 to your computer and use it in GitHub Desktop.
PKCS#1 ver 2 padding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let pkcs1v2pad key msg = | |
let blen = key.RSA.size/8 | |
and mlen = String.length msg | |
and zero = char_of_int 0 | |
and rnd = Random.string Random.secure_rng in | |
let padlen = blen - mlen in | |
if padlen > 3 then begin | |
let res = rnd padlen in | |
res.[0] <- (char_of_int 0); | |
res.[1] <- (char_of_int 2); | |
res.[padlen - 1] <- (char_of_int 0); | |
for i = 2 to padlen - 2 do | |
while res.[i] = zero do res.[i] <- (rnd 1).[0] done | |
done; | |
res ^ msg | |
end | |
else msg | |
;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment