packages feed

ciphersaber2 0.1.0.0 → 0.1.1.0

raw patch · 4 files changed

+37/−7 lines, 4 files

Files

Data/CipherSaber2.hs view
@@ -8,7 +8,7 @@ -- software for license terms. module Data.CipherSaber2 (   ByteString, rc4, encrypt, decrypt,-  toByteString, fromByteString )+  toByteString, fromByteString, ivLength )   where  import Control.Monad
README.md view
@@ -66,7 +66,7 @@ > &nbsp;&nbsp;&nbsp;&nbsp;*keystream*&nbsp;&#8592;&nbsp;zero-based array of&nbsp;*n*&nbsp;bytes   > &nbsp;&nbsp;&nbsp;&nbsp;*j*&nbsp;&#8592;&nbsp;0   > &nbsp;&nbsp;&nbsp;&nbsp;**for**&nbsp;*i*&nbsp;**in**&nbsp;0..n-1  -> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i'&nbsp;&#8592;&nbsp;*i*&nbsp;**mod**&nbsp;256  +> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i'&nbsp;&#8592;&nbsp;*(i + 1)*&nbsp;**mod**&nbsp;256   > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*j*&nbsp;&#8592;&nbsp;(*j*&nbsp;+&nbsp;*S*[i'])&nbsp;**mod**&nbsp;256   > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*S*[i']&nbsp;<->&nbsp;*S*[*j*]   > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*keystream*[*i*]&nbsp;&#8592;&nbsp;*S*[(*S*[i']&nbsp;+&nbsp;*S*[*j*])&nbsp;**mod**&nbsp;256]  
ciphersaber2.cabal view
@@ -14,7 +14,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.1.0.0+version:             0.1.1.0  -- A short (one-line) description of the package. synopsis:            Implementation of CipherSaber2 RC4 cryptography.@@ -61,7 +61,7 @@ source-repository this   type:     git   location: http://github.com/BartMassey/ciphersaber2-  tag:      v0.1.0.0+  tag:      v0.1.1.0  library   -- Modules exported by the library.
cs2.hs view
@@ -6,12 +6,15 @@ -- CipherSaber driver for UNIX-like systems with "/dev/random".  import Control.Monad-import qualified Data.ByteString.Char8 as BS+import qualified Data.ByteString as BS+import qualified Data.ByteString.Char8 as BSC import Data.CipherSaber2+import Data.Char+import Data.Word import System.Console.ParseArgs import System.IO -data ArgInd = ArgEncrypt | ArgDecrypt | ArgKey | ArgReps+data ArgInd = ArgEncrypt | ArgDecrypt | ArgKey | ArgReps | ArgIV      deriving (Ord, Eq, Show)  argd :: [ Arg ArgInd ]@@ -39,6 +42,14 @@                "(use 1 for CipherSaber-1, default 20)."   },   Arg {+     argIndex = ArgIV,+     argName = Just "iv",+     argAbbr = Just 'i',+     argData = argDataOptional "hex-string" ArgtypeString,+     argDesc = "IV as " ++ show (ivLength * 2) ++ " hex digits with" +++               " leading 0x, or " ++ show ivLength ++ " chars."+  },+  Arg {      argIndex = ArgKey,      argName = Nothing,      argAbbr = Nothing,@@ -66,7 +77,26 @@     usageError argv "Exactly one of -e or -d is required."   case e of     True -> do-      iv <- makeIV+      iv <- case getArg argv ArgIV of+              Nothing -> makeIV+              Just ivString -> return (makeBS argv ivString)       BS.interact (encrypt r k iv)     False -> do       BS.interact (decrypt r k)+  where+    makeBS argv desc+        | take 2 desc == "0x" && length desc == 2 * ivLength + 2 =+              BS.pack $ reassembleIV $ drop 2 desc+        | length desc == ivLength =+            BSC.pack desc+        | otherwise =+            usageError argv $ "IV length must be " +++                              show ivLength ++ " bytes."+        where+          reassembleIV :: String -> [Word8]+          reassembleIV "" = []+          reassembleIV (c1 : c2 : cs)+              | isHexDigit c1 && isHexDigit c2 =+                  let aByte = 16 * digitToInt c1 + digitToInt c2 in+                  fromIntegral aByte : reassembleIV cs+          reassembleIV _ = usageError argv "Bad IV string."