-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.txt
170 lines (137 loc) · 4.73 KB
/
notes.txt
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
requirements :
Makefile, author file
C, Norm
allowed functions :
open, close, read, write, malloc, free
tolerated if necessary :
strerror, exit
---------- openssl
executable : ft_ssl
Standard commands :
next project ?
Message Digest commands :
options : {
-p : echo STDIN to STDOUT and append the checksum to STDOUT
-q and -p do not modifiy output
only applies to STDIN
> echo "Do not pity the dead, Harry." | ./ft_ssl md5 -p
Do not pity the dead, Harry.
2d95365bc44bf0a298e09a3ab7b34d2f
-q : quiet mode
does not print name ?
-r : reverse the format of the input
> ./ft_ssl md5 file
MD5 (file) = 53d53ea94217b259c11a5a2d104ec58a
> ./ft_ssl md5 -r file
53d53ea94217b259c11a5a2d104ec58a file
-s : print the sum of the given string (first arg is not a file) (applies only once)
> ./ft_ssl md5 -s "pity those that aren't following baerista on spotify."
MD5 ("pity those that aren't following baerista on spotify.") = a3c990a1964705d9bf0e602f44572f5f
> echo "one more thing" | ./ft_ssl md5 -r -p -s "foo" file -s "bar"
one more thing
a0bd1876c6f011dd50fae52827f445f5
acbd18db4cc2f85cedef654fccc4a4d8 "foo"
53d53ea94217b259c11a5a2d104ec58a file
ft_ssl: md5: -s: No such file or directory
ft_ssl: md5: bar: No such file or directory
no opt : read/write from/to the console
}
syntax : {
./ft_ssl command [files]
}
must support : {
STDIN
STDOUT
files
}
md5 {
md5
openssl md5
./ft_ssl md5
len : 32 hexadecimal (128 bits) (4 * 32-bit words : A, B, C, D) (4 * 4 bytes)
Merkle–Damgård construction (https://en.wikipedia.org/wiki/Merkle%E2%80%93Damg%C3%A5rd_construction)
MD5("") = d41d8cd98f00b204e9800998ecf8427e
message padding (bits) :
first bit : 1
as many 0 necessary to obtain a length up to 64 bits (8 bytes) fewer than a multiple of 512 (64 bytes)
64 bits (8 bytes) representing the length of the message, modulo 2^64
split into 512-bit blocks (16*32-bit words)
main algorithm :
A, B, C, D initialized to predetermined fixed constants
for each 512-bit block : modify the state in four rounds
each round is composed of 16 similar operations based on a non-linear function F, modular addition, and left rotation
avalanche effect
{
possible functions :
values in little-endian
F(B, C, D) = (B & C) | (~B & D)
G(B, C, D) = (B & D) | (C & ~D)
H(B, C, D) = B ^ C ^ D
I(B, C, D) = C ^ (B | ~D)
}
{
& bitwise AND
| bitwise inclusive OR
^ bitwise XOR (exclusive OR)
<< left shift
>> right shift
~ bitwise NOT (one's complement) (unary)
}
a = 0x67452301
b = 0xefcdab89
c = 0x98badcfe
d = 0x10325476
abcd -> dabc -> cdab -> bcda
f : 7 12 17 22
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821
g : 5 9 14 20
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa
0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8
0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed
0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a
h : 4 11 7 23
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c
0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05
0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665
i : 6 10 15 21
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039
0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
}
sha256 {
sha256 (man unavailable on macs)
openssl sha -256
./ft_ssl sha256
test with shasum
len : 64 c
Big-endian convention is used when expressing the constants in this pseudocode, and when parsing message block data from bytes to words, for example, the first word of the input message "abc" after padding is 0x61626380
h0 = 0x6a09e667
h1 = 0xbb67ae85
h2 = 0x3c6ef372
h3 = 0xa54ff53a
h4 = 0x510e527f
h5 = 0x9b05688c
h6 = 0x1f83d9ab
h7 = 0x5be0cd19
k = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
}
}
bonus {
sha512
whirlpool
}
Cipher commands :
next project ?