GaloisInc / RSA

Haskell RSA Library
Other
20 stars 7 forks source link

encryptPKCS doesnt seem to work #11

Closed newsham closed 9 years ago

newsham commented 9 years ago

I am trying to use encryptPKCS and it is returning me a lazy bytestring that hangs when I convert it to a strict one. Seems to be some kind of loop going on. I'm using RSA-2.1.0.1 from cabal. The following test case will reproduce this issue:

import Codec.Crypto.RSA 
import Crypto.Random
import Crypto.Random.DRBG
import qualified Data.ByteString.Char8 as S
import qualified Data.ByteString.Lazy as L

pub = PublicKey 256 29060443439214279856616714317441381282994349643640084870421944724225051983847478784673076656611842327286248615724611803087461618516721788708203033006691375762945643318357727014263595982166729996386221650476766003639153689499857611134510522816302362939416771427488386015646066278147887150432188755545432365505792541160505770508361650791802130319371355483088627276339169052633563469569700890323453456895458435615439774655448017285792552006383801267107827169345054450617812278338175996674268312779619076725131801425088592558384516012482302720815493207137857605058069804785841016421433023935564657365714364549037012710517 65537

main = do
    g <- newGenIO :: IO (GenAutoReseed HashDRBG HashDRBG)
    let v = S.pack "testing 1 2 3"
    let (v, g') =  encryptPKCS g pub v
    -- putStrLn $ "lazy: " ++ show v                -- <<loop>> !
    putStrLn $ "strict: " ++ show (L.toStrict v) -- <<loop>> !
TomMD commented 9 years ago

@newsham isn't this just typical variable shadowing going on? Notice v is defined twice and in the second definition it creates a loop...

newsham commented 9 years ago

ack! absolutely right. I triple checked that and still missed it.. so sorry for the noise. correct test case and my original code are now working properly.