-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc28.py
30 lines (22 loc) · 787 Bytes
/
c28.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from pals.sha1 import sha1
prefix = b'foo'
def mac(data):
return sha1(prefix + data)
def validate(hash, data):
return hash == mac(data)
a = mac(b'bar')
print(validate(a, b'bar'))
'''
Implement a SHA-1 keyed MAC
Find a SHA-1 implementation in the language you code in.
Don't cheat. It won't work.
Do not use the SHA-1 implementation your language already provides
(for instance, don't use the "Digest" library in Ruby, or call OpenSSL;
in Ruby, you'd want a pure-Ruby SHA-1).
Write a function to authenticate a message under a secret key by using
a secret-prefix MAC, which is simply:
SHA1(key || message)
Verify that you cannot tamper with the message without breaking the
MAC you've produced, and that you can't produce a new MAC without
knowing the secret key.
'''