diff options
-rw-r--r-- | challenge/c28.go | 59 | ||||
-rw-r--r-- | cryptopals.go | 2 |
2 files changed, 61 insertions, 0 deletions
diff --git a/challenge/c28.go b/challenge/c28.go new file mode 100644 index 0000000..7a763d5 --- /dev/null +++ b/challenge/c28.go @@ -0,0 +1,59 @@ +// Copyright © 2021 rsiddharth <s@ricketyspace.net> +// SPDX-License-Identifier: ISC + +package challenge + +import ( + "fmt" + + "ricketyspace.net/cryptopals/lib" +) + +func C28() { + msg := lib.StrToBytes(`Nobody knows, why we keep tryin' +Why we keep tryin' + +And so on it goes, I'm looking forward +To the next letter that I'm gonna get from you + +A baby is born, as a man lay dying +As a man lay dying + +And so on it goes, I'm looking forward +To the next letter that I'm gonna get from you + +Sit beside me, watch the world burn +We'll never learn, we don't deserve nice things + +And we'll scream, self-righteously +We did our best but what does that really mean + +I'm walkin' around, walkin' around +With my head down, my head down + +I'm pushin' away, I'm pushin' away +Yeah I'm pushin' away, pushin' away`) + sec := lib.StrToBytes("Milk Records") + + // Generate SHA1 MAC. + mac := lib.Sha1Mac(sec, msg) + + // Verify. + if lib.Sha1MacVerify(sec, msg, mac) != true { + fmt.Printf("Error: Sha1Mac verification failed!\n") + return + } + + // Modify msg + msg[42] = byte(42) + + // Verify that SHA1 MAC fails + if lib.Sha1MacVerify(sec, msg, mac) != false { + fmt.Printf("Error: Sha1Mac verification success!\n") + return + } + fmt.Printf("OK\n") +} + +// Output: +// OK diff --git a/cryptopals.go b/cryptopals.go index 312d5aa..01de851 100644 --- a/cryptopals.go +++ b/cryptopals.go @@ -73,5 +73,7 @@ func main() { challenge.C26() case 27: challenge.C27() + case 28: + challenge.C28() } } |