Skip to content

Commit 4baf3ae

Browse files
committed
updated
1 parent d654f59 commit 4baf3ae

File tree

4 files changed

+45
-12
lines changed

4 files changed

+45
-12
lines changed

makefile

+16-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ifeq ($(OS),Windows_NT)
88
MV = move
99
SEP = \\
1010
else
11-
RM = $(RM) -f
11+
RM = rm -f
1212
MV = mv
1313
SEP = /
1414
endif
@@ -43,37 +43,40 @@ else
4343
endif
4444

4545
# Default target
46-
all: build static test
46+
all: _shared _static _build _test clean_o
4747

4848
# Build target for src/md files
49-
build: $(MD_BIN_FILES)
49+
_build: $(MD_BIN_FILES)
50+
build : _build clean_o
5051

5152
# Rule to compile each .c file in src/md into its corresponding binary
5253
$(BIN_DIR)/%: $(SRC_MD_DIR)/%.c | $(BIN_DIR) $(STATIC_LIB)
5354
$(CC) $(CFLAGS) -L$(LIB_DIR) -o $@ $< -lm -lmd
5455

5556
# Build target for static library
56-
static: $(STATIC_LIB)
57+
_static: $(STATIC_LIB)
58+
static : _static clean_o
5759

5860
# Rule to create the static library from src/rfc files
5961
$(STATIC_LIB): $(RFC_OBJ_FILES) | $(LIB_DIR)
6062
ar rcs $@ $(RFC_OBJ_FILES)
61-
$(RM) $(subst /,$(SEP),$(RFC_OBJ_FILES))
6263

6364
# Build target for shared library
64-
shared : $(SHARED_LIB)
65+
_shared: $(SHARED_LIB)
66+
shared : _shared clean_o
6567

6668
# Rule to create the shared library from src/rfc files
6769
$(SHARED_LIB): $(RFC_OBJ_FILES) | $(LIB_DIR)
6870
$(CC) -shared -o $@ $(RFC_OBJ_FILES)
69-
$(RM) $(subst /,$(SEP),$(RFC_OBJ_FILES))
71+
7072

7173
# Rule to compile each .c file in src/rfc into position-independent code (.o files)
7274
$(SRC_RFC_DIR)/%.o: $(SRC_RFC_DIR)/%.c
7375
$(CC) $(CFLAGS) -fPIC -c -o $@ $<
7476

7577
# Build target for test files
76-
test: $(TEST_BIN_FILES)
78+
_test: $(TEST_BIN_FILES)
79+
test : _test clean_o
7780

7881
# Rule to compile each .c file in test into its corresponding binary
7982
$(BIN_DIR)/%: $(TEST_DIR)/%.c | $(BIN_DIR) $(STATIC_LIB)
@@ -91,4 +94,8 @@ $(LIB_DIR):
9194
clean:
9295
$(RM) $(subst /,$(SEP),$(BIN_DIR)/* $(LIB_DIR)/* $(SRC_RFC_DIR)/*.o)
9396

94-
.PHONY: all build static test clean
97+
# Clean target to remove compiled binaries and libraries
98+
clean_o:
99+
$(RM) $(subst /,$(SEP),$(SRC_RFC_DIR)/*.o)
100+
101+
.PHONY: all build static shared test clean

src/rfc/rfc1320.c

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ uint8_t *MD4(uint8_t *message, uint64_t message_len, uint8_t *digest)
127127
C += CC;
128128
D += DD;
129129
}
130+
printf("F >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
130131

131132
uint32_t ABCD[] = {A, B, C, D};
132133

src/rfc/rfc1321.c

+18
Original file line numberDiff line numberDiff line change
@@ -61,91 +61,109 @@ uint8_t *MD5(uint8_t *message, uint64_t message_len, uint8_t *digest)
6161
_a5(&D, A, B, C, 1, 12, 2, F, X);
6262
_a5(&C, D, A, B, 2, 17, 3, F, X);
6363
_a5(&B, C, D, A, 3, 22, 4, F, X);
64+
printf("1 >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
6465

6566
_a5(&A, B, C, D, 4, 7, 5, F, X);
6667
_a5(&D, A, B, C, 5, 12, 6, F, X);
6768
_a5(&C, D, A, B, 6, 17, 7, F, X);
6869
_a5(&B, C, D, A, 7, 22, 8, F, X);
70+
printf("1 >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
6971

7072
_a5(&A, B, C, D, 8, 7, 9, F, X);
7173
_a5(&D, A, B, C, 9, 12, 10, F, X);
7274
_a5(&C, D, A, B, 10, 17, 11, F, X);
7375
_a5(&B, C, D, A, 11, 22, 12, F, X);
76+
printf("1 >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
7477

7578
_a5(&A, B, C, D, 12, 7, 13, F, X);
7679
_a5(&D, A, B, C, 13, 12, 14, F, X);
7780
_a5(&C, D, A, B, 14, 17, 15, F, X);
7881
_a5(&B, C, D, A, 15, 22, 16, F, X);
82+
printf("1 >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
7983

8084
// Round 2
8185
_a5(&A, B, C, D, 1, 5, 17, G, X);
8286
_a5(&D, A, B, C, 6, 9, 18, G, X);
8387
_a5(&C, D, A, B, 11, 14, 19, G, X);
8488
_a5(&B, C, D, A, 0, 20, 20, G, X);
89+
printf("2 >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
8590

8691
_a5(&A, B, C, D, 5, 5, 21, G, X);
8792
_a5(&D, A, B, C, 10, 9, 22, G, X);
8893
_a5(&C, D, A, B, 15, 14, 23, G, X);
8994
_a5(&B, C, D, A, 4, 20, 24, G, X);
95+
printf("2 >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
9096

9197
_a5(&A, B, C, D, 9, 5, 25, G, X);
9298
_a5(&D, A, B, C, 14, 9, 26, G, X);
9399
_a5(&C, D, A, B, 3, 14, 27, G, X);
94100
_a5(&B, C, D, A, 8, 20, 28, G, X);
101+
printf("2 >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
95102

96103
_a5(&A, B, C, D, 13, 5, 29, G, X);
97104
_a5(&D, A, B, C, 2, 9, 30, G, X);
98105
_a5(&C, D, A, B, 7, 14, 31, G, X);
99106
_a5(&B, C, D, A, 12, 20, 32, G, X);
107+
printf("2 >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
100108

101109
// Round 3
102110
_a5(&A, B, C, D, 5, 4, 33, H, X);
103111
_a5(&D, A, B, C, 8, 11, 34, H, X);
104112
_a5(&C, D, A, B, 11, 16, 35, H, X);
105113
_a5(&B, C, D, A, 14, 23, 36, H, X);
114+
printf("3 >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
106115

107116
_a5(&A, B, C, D, 1, 4, 37, H, X);
108117
_a5(&D, A, B, C, 4, 11, 38, H, X);
109118
_a5(&C, D, A, B, 7, 16, 39, H, X);
110119
_a5(&B, C, D, A, 10, 23, 40, H, X);
120+
printf("3 >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
111121

112122
_a5(&A, B, C, D, 13, 4, 41, H, X);
113123
_a5(&D, A, B, C, 0, 11, 42, H, X);
114124
_a5(&C, D, A, B, 3, 16, 43, H, X);
115125
_a5(&B, C, D, A, 6, 23, 44, H, X);
126+
printf("3 >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
116127

117128
_a5(&A, B, C, D, 9, 4, 45, H, X);
118129
_a5(&D, A, B, C, 12, 11, 46, H, X);
119130
_a5(&C, D, A, B, 15, 16, 47, H, X);
120131
_a5(&B, C, D, A, 2, 23, 48, H, X);
132+
printf("3 >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
121133

122134
// Round 4
123135
_a5(&A, B, C, D, 0, 6, 49, I, X);
124136
_a5(&D, A, B, C, 7, 10, 50, I, X);
125137
_a5(&C, D, A, B, 14, 15, 51, I, X);
126138
_a5(&B, C, D, A, 5, 21, 52, I, X);
139+
printf("4 >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
127140

128141
_a5(&A, B, C, D, 12, 6, 53, I, X);
129142
_a5(&D, A, B, C, 3, 10, 54, I, X);
130143
_a5(&C, D, A, B, 10, 15, 55, I, X);
131144
_a5(&B, C, D, A, 1, 21, 56, I, X);
145+
printf("4 >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
132146

133147
_a5(&A, B, C, D, 8, 6, 57, I, X);
134148
_a5(&D, A, B, C, 15, 10, 58, I, X);
135149
_a5(&C, D, A, B, 6, 15, 59, I, X);
136150
_a5(&B, C, D, A, 13, 21, 60, I, X);
151+
printf("4 >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
137152

138153
_a5(&A, B, C, D, 4, 6, 61, I, X);
139154
_a5(&D, A, B, C, 11, 10, 62, I, X);
140155
_a5(&C, D, A, B, 2, 15, 63, I, X);
141156
_a5(&B, C, D, A, 9, 21, 64, I, X);
157+
printf("4 >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
142158

143159
A += AA;
144160
B += BB;
145161
C += CC;
146162
D += DD;
147163
}
148164

165+
printf("F >> A: %08X B: %08X C: %08X D: %08X\n", A, B, C, D);
166+
149167
uint32_t ABCD[] = {A, B, C, D};
150168

151169
for (size_t i = 0; i < 4; ++i)

test/test_all.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ int main()
3535
{0x5e, 0x4c, 0x4d, 0x1b, 0xe9, 0xb0, 0xfe, 0x14, 0x2b, 0xb6, 0x78, 0x27, 0xc2, 0x19, 0xa7, 0x95},
3636
{0xcd, 0x4c, 0xd8, 0x8a, 0xac, 0x34, 0xf8, 0x26, 0xab, 0x00, 0x5d, 0x00, 0xf8, 0x14, 0x1e, 0xc1}};
3737

38+
uint8_t md5_expecteds[][16] = {
39+
{0x0c, 0xc1, 0x75, 0xb9, 0xc0, 0xf1, 0xb6, 0xa8, 0x31, 0xc3, 0x99, 0xe2, 0x69, 0x77, 0x26, 0x61},
40+
{0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0, 0xd6, 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72},
41+
{0xd0, 0xcf, 0x3d, 0x6c, 0xee, 0xc4, 0xad, 0xfc, 0x5e, 0x57, 0xf9, 0xb4, 0x88, 0x88, 0x35, 0xd0},
42+
{0x8c, 0x4d, 0x8f, 0x13, 0x5c, 0xba, 0xbe, 0x82, 0x8c, 0x2e, 0x14, 0x0c, 0x32, 0x8b, 0xe3, 0xd0},
43+
{0xa9, 0x82, 0xc1, 0x34, 0x93, 0xc5, 0x39, 0x96, 0x0f, 0x6f, 0xf3, 0xb9, 0x66, 0x21, 0xfd, 0x64}};
44+
3845
uint8_t md2_digest[MD2_DIGEST_LENGTH];
3946
uint8_t md4_digest[MD4_DIGEST_LENGTH];
4047
uint8_t md5_digest[MD5_DIGEST_LENGTH];
@@ -77,13 +84,13 @@ int main()
7784
printf("\n");
7885
printf("message : %s\n", messages[i]);
7986
printf("expected: ");
80-
print_hex(md4_expecteds[i], 16);
87+
print_hex(md5_expecteds[i], 16);
8188
printf("\n");
8289
MD5(messages[i], strlen((char *)messages[i]), md5_digest);
8390
printf("output : ");
84-
print_hex(md4_digest, 16);
91+
print_hex(md5_digest, 16);
8592
printf("\n");
86-
printf("matches?: %s\n", memcmp(md5_digest, md4_expecteds[i], 16) ? "false" : "true");
93+
printf("matches?: %s\n", memcmp(md5_digest, md5_expecteds[i], 16) ? "false" : "true");
8794
}
8895
printf("\n===============\n");
8996

0 commit comments

Comments
 (0)