Skip to content

Commit

Permalink
update stegoparams
Browse files Browse the repository at this point in the history
  • Loading branch information
sigrdrifa committed Dec 1, 2023
1 parent b3dd0be commit 82a88b6
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 52 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,3 @@ benchmark-pattern:

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.* ?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: all $(MAKECMDGOALS)
2 changes: 2 additions & 0 deletions audiocate.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ test-suite audiocate-test
, EncodeCmdSpec
, EncodeStreamCmdSpec
, DecodeStreamCmdSpec
, StegoSpec
ghc-options:
-O -threaded -rtsopts -with-rtsopts=-N
build-tool-depends:
Expand All @@ -125,6 +126,7 @@ test-suite audiocate-test
, mtl
, hspec
, hspec-discover
, time

benchmark bench
default-language: GHC2021
Expand Down
8 changes: 4 additions & 4 deletions lib/Command/Cmd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ interpretCmd cmd =
(Encode secret timeRange inputFile outputFile) -> do
let s = encodeUtf8 (T.pack secret)
let t :: Word64 = fromIntegral timeRange
let stegoParams = StegoParams s t 6 LsbEncoding 0
let stegoParams = StegoParams s t 6 LsbEncoding 0 False
runEncodeCmd stegoParams inputFile outputFile
pure CmdSuccess
(EncodeStream secret timeRange inputFile outputFile) -> do
let s = encodeUtf8 (T.pack secret)
let t :: Word64 = fromIntegral timeRange
let stegoParams = StegoParams s t 6 LsbEncoding 0
let stegoParams = StegoParams s t 6 LsbEncoding 0 False
runEncodeStreamCmd False stegoParams inputFile outputFile
pure CmdSuccess
(Decode secret timeRange inputFile) -> do
let s = encodeUtf8 (T.pack secret)
let t :: Word64 = fromIntegral timeRange
let stegoParams = StegoParams s t 6 LsbEncoding 0
let stegoParams = StegoParams s t 6 LsbEncoding 0 False
runDecodeCmd stegoParams inputFile
pure CmdSuccess
(DecodeStream secret timeRange inputFile) -> do
let s = encodeUtf8 (T.pack secret)
let t :: Word64 = fromIntegral timeRange
let stegoParams = StegoParams s t 6 LsbEncoding 0
let stegoParams = StegoParams s t 6 LsbEncoding 0 False
runDecodeStreamCmd False stegoParams inputFile
pure CmdSuccess
8 changes: 4 additions & 4 deletions lib/Stego/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ type DecodedPayload = (Word64, TotpPayload)
type DecodedFrame = (Int, [Int16], DecodedPayload)

-- | StegoParams instance used to capture parameters
data StegoParams = StegoParams Secret Word64 Word8 EncodingType Payload
data StegoParams = StegoParams Secret Word64 Word8 EncodingType Payload Bool
deriving (Show, Eq)

-- | Extracts the EncodingType of provided StegoParams
getEncodingType :: StegoParams -> EncodingType
getEncodingType (StegoParams _ _ _ LsbEncoding _) = LsbEncoding
getEncodingType (StegoParams _ _ _ LsbEncoding _ _) = LsbEncoding
getEncodingType _ = EchoHideEncoding

-- | Calculates a TOTP value for the StegoParams at the provided UTCTime
calculateTotp :: StegoParams -> UTCTime -> TotpPayload
calculateTotp (StegoParams secret range numDigits _ _) time =
calculateTotp (StegoParams secret range numDigits _ _ _) time =
totp SHA1 secret time range numDigits

-- | Checks if the provided TOTP value is valid for the given time and
-- stego params
checkTotp :: StegoParams -> UTCTime -> TotpPayload -> Bool
checkTotp (StegoParams secret range numDigits _ _) time =
checkTotp (StegoParams secret range numDigits _ _ _) time =
totpCheck SHA1 secret (0, 0) time range numDigits

-- | Converts a UTCTime into Word64 representation of POSIX seconds since epoch
Expand Down
2 changes: 1 addition & 1 deletion test/EncodeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec =
do
let secret = encodeUtf8 (T.pack "test-secret")
let timeValid :: Word64 = 5
let stegoParams = StegoParams secret timeValid 6 LsbEncoding 0
let stegoParams = StegoParams secret timeValid 6 LsbEncoding 0 False
context "when passing it an empty frames list" $
it "should return an empty encode result" $ do
encoder <- newEncoder stegoParams
Expand Down
17 changes: 17 additions & 0 deletions test/StegoSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module StegoSpec
( spec
) where
import Test.Hspec
import Stego.Common
import Data.Time.Clock.POSIX (posixSecondsToUTCTime, utcTimeToPOSIXSeconds)

spec :: Spec
spec =
describe "Tests the StegoCommon module functionality" $
-- setup test vars
do
it "tests the utcTimeToWord64 and word64ToUtcTime functions" $ do
let t = utcTimeToWord64 $ posixSecondsToUTCTime 1.999999
t `shouldBe` 2
let t = utcTimeToWord64 $ posixSecondsToUTCTime 1.9999999
t `shouldBe` 2
12 changes: 6 additions & 6 deletions test/output/bench_results.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Name,Mean (ps),2*Stdev (ps),Allocated,Copied,Peak Memory
All.EncodeStreamCmd.encodestream sample1,13331950550,987441022,92316505,6239,39845888
All.EncodeStreamCmd.encodestream sample2,157690056200,8586908444,1026804541,33874,39845888
All.EncodeStreamCmd.encodestream sample3,24051070500,1060021440,149445797,9319,39845888
All.DecodeStreamCmd.decodestream sample1,312094441,12317934,1628426,44,78643200
All.DecodeStreamCmd.decodestream sample2,3774645087,373300452,17228076,527,78643200
All.DecodeStreamCmd.decodestream sample3,486733567,14118744,2620858,73,78643200
All.EncodeStreamCmd.encodestream sample1,15040768593,894801872,93855144,6416,39845888
All.EncodeStreamCmd.encodestream sample2,158199655200,12267294320,1019767834,36963,39845888
All.EncodeStreamCmd.encodestream sample3,24438984900,1077451814,149445165,9364,39845888
All.DecodeStreamCmd.decodestream sample1,331582348,22610820,1614401,46,78643200
All.DecodeStreamCmd.decodestream sample2,3874140531,333099360,17228100,525,78643200
All.DecodeStreamCmd.decodestream sample3,495499743,25715734,2620860,74,78643200
70 changes: 35 additions & 35 deletions test/output/bench_results.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 82a88b6

Please sign in to comment.