Commit 79b3a0b7f48918a36f56444d828b11e5f7bbd0cc

Guillem Jover 2011-05-29T04:48:16

build: Add build infrastructure

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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3dd8333
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,24 @@
+ChangeLog
+*.a
+*.o
+*.la
+*.lo
+*.pc
+*.so
+*.so.*
+*hl.c
+*.log
+*.trs
+.deps/
+.libs/
+Makefile
+Makefile.in
+/aclocal.m4
+/autom4te.cache/
+/build-aux/
+/ChangeLog
+/config.*
+/configure
+/libtool
+/m4/
+/stamp-h1
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..9f2c0db
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,179 @@
+Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+
+Files:
+ *
+Copyright:
+ Copyright © 2009, 2016 Guillem Jover <guillem@hadrons.org>
+License: BSD-3-clause
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+ 3. The name of the author may not be used to endorse or promote products
+    derived from this software without specific prior written permission.
+ .
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Files:
+ include/sha2.h
+ man/sha2.3
+ src/sha2.c
+Copyright:
+ Copyright © 2000-2001, Aaron D. Gifford
+ All rights reserved.
+License: BSD-3-clause-Aaron-D-Gifford
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of contributors
+    may be used to endorse or promote products derived from this software
+    without specific prior written permission.
+ .
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+Files:
+ include/rmd160.h
+ man/rmd160.3
+ src/rmd160.c
+Copyright:
+ Copyright © 2001 Markus Friedl.  All rights reserved.
+License: BSD-2-clause
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+ .
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Files:
+ src/md2.c
+Copyright:
+ Copyright (c) 2001 The NetBSD Foundation, Inc.
+ All rights reserved.
+ .
+ This code is derived from software contributed to The NetBSD Foundation
+ by Andrew Brown.
+License: BSD-2-clause-NetBSD
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+ .
+ THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+Files:
+ man/rmd160.3
+ man/sha1.3
+ man/sha2.3
+Copyright:
+ Copyright © 1997, 2003, 2004 Todd C. Miller <Todd.Miller@courtesan.com>
+License: ISC
+ Permission to use, copy, modify, and distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+ .
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+Files:
+ man/mdX.3
+ src/helper.c
+Copyright:
+ Poul-Henning Kamp <phk@login.dkuug.dk>
+License: Beerware
+ "THE BEER-WARE LICENSE" (Revision 42):
+ <phk@login.dkuug.dk> wrote this file.  As long as you retain this notice you
+ can do whatever you want with this stuff. If we meet some day, and you think
+ this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
+
+Files:
+ include/md4.h
+ src/md4.c
+Copyright:
+ Colin Plumb
+ Todd C. Miller
+License: public-domain-md4
+ This code implements the MD4 message-digest algorithm.
+ The algorithm is due to Ron Rivest.  This code was
+ written by Colin Plumb in 1993, no copyright is claimed.
+ This code is in the public domain; do with it what you wish.
+ Todd C. Miller modified the MD5 code to do MD4 based on RFC 1186.
+
+Files:
+ include/md5.h
+ src/md5.c
+Copyright:
+ Colin Plumb
+License: public-domain-md5
+ This code implements the MD5 message-digest algorithm.
+ The algorithm is due to Ron Rivest.  This code was
+ written by Colin Plumb in 1993, no copyright is claimed.
+ This code is in the public domain; do with it what you wish.
+
+Files:
+ include/sha1.h
+ src/sha1.c
+Copyright:
+ Steve Reid <steve@edmweb.com>
+License: public-domain-sha1
+ 100% Public Domain
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..b839ae1
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,16 @@
+## Process this file with automake to produce Makefile.in
+
+SUBDIRS = include man src test
+
+ACLOCAL_AMFLAGS = -I m4
+
+EXTRA_DIST = \
+	autogen \
+	get-version \
+	$(nil)
+
+dist-hook:
+	echo $(VERSION) >$(distdir)/.dist-version
+	if [ -d .git ]; then \
+	  XDG_CONFIG_HOME= HOME= git log --stat -C >$(distdir)/ChangeLog; \
+	fi
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..fc1066a
--- /dev/null
+++ b/NEWS
@@ -0,0 +1,3 @@
+0.0.0 (git)
+
+	Initial release.
diff --git a/README b/README
new file mode 100644
index 0000000..e8d532f
--- /dev/null
+++ b/README
@@ -0,0 +1,38 @@
+libmd - Message Digest functions from BSD systems
+
+This library provides message digest functions found on BSD systems either
+on their libc or libmd libraries and lacking on others like GNU systems,
+thus making it easier to port projects with strong BSD origins, without
+needing to embed the same code over and over again on each project.
+
+
+Website
+-------
+
+The project website can be found at:
+
+  <https://www.hadrons.org/software/libmd/>
+
+
+Mailing List
+------------
+
+The subscription interface and web archives can be found at:
+
+  <https://lists.freedesktop.org/mailman/listinfo/libbsd>
+
+The mail address is:
+
+  libbsd@lists.freedesktop.org
+
+
+Releases
+--------
+
+  <https://archive.hadrons.org/software/libmd/>
+
+
+Source Repository
+-----------------
+
+  <https://git.hadrons.org/cgit/libmd.git>
diff --git a/autogen b/autogen
new file mode 100755
index 0000000..7cf1815
--- /dev/null
+++ b/autogen
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+mkdir -p m4
+autoreconf -f -i
+rm -rf autom4te.cache
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..330e8cb
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,54 @@
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ([2.68])
+AC_INIT([libmd], [m4_esyscmd([./get-version])], [libbsd@lists.freedesktop.org])
+AC_CONFIG_SRCDIR([src/sha2.c])
+AC_CONFIG_AUX_DIR([build-aux])
+AC_CONFIG_MACRO_DIR([m4])
+
+AM_INIT_AUTOMAKE([1.8 -Wall foreign nostdinc no-dist-gzip dist-xz])
+
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
+                            [AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
+
+LIBMD_ABI_MAJOR=0
+LIBMD_ABI_MINOR=0
+LIBMD_ABI_PATCH=0
+
+LIBMD_ABI="$LIBMD_ABI_MAJOR:$LIBMD_ABI_MINOR:$LIBMD_ABI_PATCH"
+AC_SUBST([LIBMD_ABI])
+
+# Checks for operating system services and capabilities.
+AC_USE_SYSTEM_EXTENSIONS
+AC_SYS_LARGEFILE
+
+AM_PROG_AR
+LT_INIT
+
+# Checks for programs.
+AC_PROG_CC
+
+# Checks for libraries.
+
+# Checks for header files.
+AC_CHECK_HEADERS([sys/param.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_TYPE_OFF_T
+AC_TYPE_SIZE_T
+AC_TYPE_SSIZE_T
+
+# Checks for library functions.
+AC_FUNC_MALLOC
+AC_CHECK_FUNCS([memset])
+
+AC_CONFIG_FILES([
+	Makefile
+	include/Makefile
+	man/Makefile
+	src/Makefile
+	src/libmd.pc
+	test/Makefile
+])
+AC_CONFIG_HEADERS([config.h])
+AC_OUTPUT
diff --git a/get-version b/get-version
new file mode 100755
index 0000000..4253eb7
--- /dev/null
+++ b/get-version
@@ -0,0 +1,50 @@
+#!/bin/sh
+#
+# get-version
+#
+# Copyright © 2009 Guillem Jover <guillem@hadrons.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. The name of the author may not be used to endorse or promote products
+#    derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+# THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+if [ -f .dist-version ]; then
+  # Get the version from the file distributed in the tarball.
+  version=$(cat .dist-version)
+elif [ -d .git ]; then
+  # Ger the version from the git repository.
+  version=$(git describe --abbrev=4 HEAD 2>/dev/null)
+  if [ -z "$version" ]; then
+    version="initial"
+  fi
+
+  # Check if we are on a dirty checkout.
+  git update-index --refresh -q >/dev/null
+  dirty=$(git diff-index --name-only HEAD 2>/dev/null)
+  if [ -n "$dirty" ]; then
+    version="$version-dirty"
+  fi
+else
+  echo "error: cannot get project version." 1>&2
+  exit 1
+fi
+
+printf "$version"
diff --git a/include/Makefile.am b/include/Makefile.am
new file mode 100644
index 0000000..2fef6bc
--- /dev/null
+++ b/include/Makefile.am
@@ -0,0 +1,10 @@
+## Process this file with automake to produce Makefile.in
+
+include_HEADERS = \
+	md2.h \
+	md4.h \
+	md5.h \
+	rmd160.h \
+	sha1.h \
+	sha2.h \
+	$(nil)
diff --git a/man/.gitignore b/man/.gitignore
new file mode 100644
index 0000000..eb75a35
--- /dev/null
+++ b/man/.gitignore
@@ -0,0 +1,3 @@
+md2.3
+md4.3
+md5.3
diff --git a/man/Makefile.am b/man/Makefile.am
new file mode 100644
index 0000000..a919705
--- /dev/null
+++ b/man/Makefile.am
@@ -0,0 +1,148 @@
+EXTRA_DIST = \
+	mdX.3 \
+	$(nil)
+
+CLEANFILES = \
+	md4.3 \
+	md5.3 \
+	$(nil)
+
+SED_MD2_SUBST = -e 's/mdX/md2/g' -e 's/MDX/MD2/g'
+SED_MD4_SUBST = -e 's/mdX/md4/g' -e 's/MDX/MD4/g'
+SED_MD5_SUBST = -e 's/mdX/md5/g' -e 's/MDX/MD5/g'
+
+md2.3: $(srcdir)/mdX.3
+	$(AM_V_GEN) sed $(SED_MD2_SUBST) $< >$@
+
+md4.3: $(srcdir)/mdX.3
+	$(AM_V_GEN) sed $(SED_MD4_SUBST) $< >$@
+
+md5.3: $(srcdir)/mdX.3
+	$(AM_V_GEN) sed $(SED_MD5_SUBST) $< >$@
+
+dist_man_MANS = \
+	md2.3 \
+	md4.3 \
+	md5.3 \
+	rmd160.3 \
+	sha1.3 \
+	sha2.3 \
+	$(nil)
+
+md2_FUNCS = \
+	MD2Transform \
+	MD2Init \
+	MD2Final \
+	MD2Update \
+	MD2End \
+	MD2File \
+	MD2FileChunk \
+	MD2Data \
+	$(nil)
+
+$(md2_FUNCS): md2.3
+	$(LN_S) -f $< $(DESTDIR)$(man3dir)/$@.3
+
+md4_FUNCS = \
+	MD4Transform \
+	MD4Init \
+	MD4Final \
+	MD4Update \
+	MD4End \
+	MD4File \
+	MD4FileChunk \
+	MD4Pad \
+	MD4Data \
+	$(nil)
+
+$(md4_FUNCS): md4.3
+	$(LN_S) -f $< $(DESTDIR)$(man3dir)/$@.3
+
+md5_FUNCS = \
+	MD5Transform \
+	MD5Init \
+	MD5Final \
+	MD5Update \
+	MD5End \
+	MD5File \
+	MD5FileChunk \
+	MD5Pad \
+	MD5Data \
+	$(nil)
+
+$(md5_FUNCS): md5.3
+	$(LN_S) -f $< $(DESTDIR)$(man3dir)/$@.3
+
+rmd160_FUNCS = \
+	RMD160Transform \
+	RMD160Init \
+	RMD160Final \
+	RMD160Update \
+	RMD160End \
+	RMD160File \
+	RMD160FileChunk \
+	RMD160Pad \
+	RMD160Data \
+	$(nil)
+
+$(rmd160_FUNCS): rmd160.3
+	$(LN_S) -f $< $(DESTDIR)$(man3dir)/$@.3
+
+sha1_FUNCS = \
+	SHA1Transform \
+	SHA1Init \
+	SHA1Final \
+	SHA1Update \
+	SHA1End \
+	SHA1File \
+	SHA1FileChunk \
+	SHA1Pad \
+	SHA1Data \
+	$(nil)
+
+$(sha1_FUNCS): sha1.3
+	$(LN_S) -f $< $(DESTDIR)$(man3dir)/$@.3
+
+sha2_FUNCS = \
+	SHA256Init \
+	SHA256Update \
+	SHA256Pad \
+	SHA256Final \
+	SHA256Transform \
+	SHA256End \
+	SHA256File \
+	SHA256FileChunk \
+	SHA256Data \
+	SHA384Init \
+	SHA384Update \
+	SHA384Pad \
+	SHA384Final \
+	SHA384Transform \
+	SHA384End \
+	SHA384File \
+	SHA384FileChunk \
+	SHA384Data \
+	SHA512Init \
+	SHA512Update \
+	SHA512Pad \
+	SHA512Final \
+	SHA512Transform \
+	SHA512End \
+	SHA512File \
+	SHA512FileChunk \
+	SHA512Data \
+	$(nil)
+
+$(sha2_FUNCS): sha2.3
+	$(LN_S) -f $< $(DESTDIR)$(man3dir)/$@.3
+
+digest_FUNCS = \
+	$(md2_FUNCS) \
+	$(md4_FUNCS) \
+	$(md5_FUNCS) \
+	$(rmd160_FUNCS) \
+	$(sha1_FUNCS) \
+	$(sha2_FUNCS) \
+	$(nil)
+
+install-data-hook: $(digest_FUNCS)
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..f2209e6
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,97 @@
+## Process this file with automake to produce Makefile.in
+
+AM_CPPFLAGS = \
+	-I$(top_srcdir)/include \
+	-include $(top_builddir)/config.h
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = \
+	libmd.pc \
+	$(nil)
+
+lib_LTLIBRARIES = libmd.la
+
+libmd_la_helper_sources = \
+	md2hl.c \
+	md4hl.c \
+	md5hl.c \
+	rmd160hl.c \
+	sha1hl.c \
+	sha256hl.c \
+	sha384hl.c \
+	sha512hl.c \
+	$(nil)
+
+libmd_la_LDFLAGS = \
+	-Wl,--version-script=$(srcdir)/libmd.map \
+	-version-number $(LIBMD_ABI)
+libmd_la_DEPENDENCIES = \
+	libmd.map \
+	helper.c \
+	$(nil)
+libmd_la_SOURCES = \
+	md2.c \
+	md4.c \
+	md5.c \
+	rmd160.c \
+	sha1.c \
+	sha2.c \
+	$(libmd_la_helper_sources) \
+	$(nil)
+
+BUILT_SOURCES = \
+	$(libmd_la_helper_sources) \
+	$(nil)
+
+EXTRA_DIST = \
+	libmd.map \
+	libmd.pc.in \
+	helper.c \
+	$(nil)
+
+CLEANFILES = \
+	$(libmd_la_helper_sources) \
+	$(nil)
+
+md2hl.c: helper.c
+	$(AM_V_GEN) sed -e 's/hashinc/md2.h/g' -e 's/HASH/MD2/g' $< > $@
+
+md4hl.c: helper.c
+	$(AM_V_GEN) sed -e 's/hashinc/md4.h/g' -e 's/HASH/MD4/g' $< > $@
+
+md5hl.c: helper.c
+	$(AM_V_GEN) sed -e 's/hashinc/md5.h/g' -e 's/HASH/MD5/g' $< > $@
+
+rmd160hl.c: helper.c
+	$(AM_V_GEN) sed -e 's/hashinc/rmd160.h/g' -e 's/HASH/RMD160/g' $< > $@
+
+sha1hl.c: helper.c
+	$(AM_V_GEN) sed -e 's/hashinc/sha1.h/g' -e 's/HASH/SHA1/g' $< > $@
+
+sha256hl.c: helper.c
+	$(AM_V_GEN) sed -e 's/hashinc/sha2.h/g' -e 's/HASH/SHA256/g' \
+	                -e 's/SHA[0-9][0-9][0-9]_CTX/SHA2_CTX/g' $< > $@
+
+sha384hl.c: helper.c
+	$(AM_V_GEN) sed -e 's/hashinc/sha2.h/g' -e 's/HASH/SHA384/g' \
+	                -e 's/SHA[0-9][0-9][0-9]_CTX/SHA2_CTX/g' $< > $@
+
+sha512hl.c: helper.c
+	$(AM_V_GEN) sed -e 's/hashinc/sha2.h/g' -e 's/HASH/SHA512/g' \
+	                -e 's/SHA[0-9][0-9][0-9]_CTX/SHA2_CTX/g' $< > $@
+
+runtimelibdir = $(libdir)
+
+install-exec-hook:
+	if [ "$(libdir)" != "$(runtimelibdir)" ]; then \
+		$(MKDIR_P) $(DESTDIR)$(runtimelibdir); \
+		mv $(DESTDIR)$(libdir)/libmd*.so.* \
+		   $(DESTDIR)$(runtimelibdir)/; \
+		soname=`readlink $(DESTDIR)$(libdir)/libmd.so`; \
+		sorelprefix=`echo $(libdir) | sed -r -e 's:(^/)?[^/]+:..:g'`; \
+		ln -sf $$sorelprefix$(runtimelibdir)/$$soname \
+		       $(DESTDIR)$(libdir)/libmd.so; \
+	fi
+
+uninstall-hook:
+	rm -f $(DESTDIR)$(runtimelibdir)/libmd*.so*
diff --git a/src/libmd.map b/src/libmd.map
new file mode 100644
index 0000000..fd4d579
--- /dev/null
+++ b/src/libmd.map
@@ -0,0 +1,84 @@
+LIBMD_0.0 {
+global:
+	MD2Data;
+	MD2End;
+	MD2File;
+	MD2FileChunk;
+	MD2Final;
+	MD2Init;
+	MD2Update;
+	MD2Transform;
+
+	MD4Data;
+	MD4End;
+	MD4File;
+	MD4FileChunk;
+	MD4Final;
+	MD4Init;
+	MD4Pad;
+	MD4Transform;
+	MD4Update;
+
+	MD5Data;
+	MD5End;
+	MD5File;
+	MD5FileChunk;
+	MD5Final;
+	MD5Init;
+	MD5Pad;
+	MD5Transform;
+	MD5Update;
+
+	RMD160Data;
+	RMD160End;
+	RMD160File;
+	RMD160FileChunk;
+	RMD160Final;
+	RMD160Init;
+	RMD160Pad;
+	RMD160Transform;
+	RMD160Update;
+
+	SHA1Data;
+	SHA1End;
+	SHA1File;
+	SHA1FileChunk;
+	SHA1Final;
+	SHA1Init;
+	SHA1Pad;
+	SHA1Transform;
+	SHA1Update;
+
+	SHA256Data;
+	SHA256End;
+	SHA256File;
+	SHA256FileChunk;
+	SHA256Final;
+	SHA256Init;
+	SHA256Pad;
+	SHA256Transform;
+	SHA256Update;
+
+	SHA384Data;
+	SHA384End;
+	SHA384File;
+	SHA384FileChunk;
+	SHA384Final;
+	SHA384Init;
+	SHA384Pad;
+	SHA384Transform;
+	SHA384Update;
+
+	SHA512Data;
+	SHA512End;
+	SHA512File;
+	SHA512FileChunk;
+	SHA512Final;
+	SHA512Init;
+	SHA512Pad;
+	SHA512Transform;
+	SHA512Update;
+
+local:
+	*;
+};
diff --git a/src/libmd.pc.in b/src/libmd.pc.in
new file mode 100644
index 0000000..0ff35b3
--- /dev/null
+++ b/src/libmd.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libmd
+Description: Message Digest functions from BSD systems
+Version: @VERSION@
+URL: https://www.hadrons.org/software/libmd/
+Libs: -L${libdir} -lmd
+Cflags: -I${includedir}
diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644
index 0000000..3d09458
--- /dev/null
+++ b/test/.gitignore
@@ -0,0 +1,6 @@
+md2
+md4
+md5
+rmd160
+sha1
+sha2
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..8a4512e
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,20 @@
+## Process this file with automake to produce Makefile.in
+
+AM_CPPFLAGS = \
+	-include $(top_builddir)/config.h \
+	-I$(top_builddir) \
+	-I$(top_srcdir)/include \
+	$(nil)
+
+LDADD = $(top_builddir)/src/libmd.la
+
+check_PROGRAMS = \
+	md2 \
+	md4 \
+	md5 \
+	rmd160 \
+	sha1 \
+	sha2 \
+	$(nil)
+
+TESTS = $(check_PROGRAMS)
diff --git a/test/md2.c b/test/md2.c
new file mode 100644
index 0000000..01849e0
--- /dev/null
+++ b/test/md2.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2016 Guillem Jover <guillem@hadrons.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <assert.h>
+#include <md2.h>
+#include <string.h>
+
+void
+test_md2(const char *digest, const char *string)
+{
+	char result[MD2_DIGEST_STRING_LENGTH];
+
+	assert(strcmp(digest, MD2Data(string, strlen(string), result)) == 0);
+}
+
+int
+main()
+{
+	test_md2("8350e5a3e24c153df2275c9f80692773", "");
+	test_md2("da853b0d3f88d99b30283a69e6ded6bb", "abc");
+	test_md2("2fe3cb9e21922819e79a2781af74e36d", "12345");
+
+	return 0;
+}
diff --git a/test/md4.c b/test/md4.c
new file mode 100644
index 0000000..177ed3d
--- /dev/null
+++ b/test/md4.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2016 Guillem Jover <guillem@hadrons.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <assert.h>
+#include <md4.h>
+#include <string.h>
+
+void
+test_md4(const char *digest, const char *string)
+{
+	char result[MD4_DIGEST_STRING_LENGTH];
+
+	assert(strcmp(digest, MD4Data(string, strlen(string), result)) == 0);
+}
+
+int
+main()
+{
+	test_md4("31d6cfe0d16ae931b73c59d7e0c089c0", "");
+	test_md4("a448017aaf21d8525fc10ae87aa6729d", "abc");
+	test_md4("23580e2a459f7ea40f9efa148b63cafb", "12345");
+
+	return 0;
+}
diff --git a/test/md5.c b/test/md5.c
new file mode 100644
index 0000000..7fd3833
--- /dev/null
+++ b/test/md5.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2016 Guillem Jover <guillem@hadrons.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <assert.h>
+#include <md5.h>
+#include <string.h>
+
+void
+test_md5(const char *digest, const char *string)
+{
+	char result[MD5_DIGEST_STRING_LENGTH];
+
+	assert(strcmp(digest, MD5Data(string, strlen(string), result)) == 0);
+}
+
+int
+main()
+{
+	test_md5("d41d8cd98f00b204e9800998ecf8427e", "");
+	test_md5("900150983cd24fb0d6963f7d28e17f72", "abc");
+	test_md5("827ccb0eea8a706c4c34a16891f84e7b", "12345");
+
+	return 0;
+}
diff --git a/test/rmd160.c b/test/rmd160.c
new file mode 100644
index 0000000..b4adbcf
--- /dev/null
+++ b/test/rmd160.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2016 Guillem Jover <guillem@hadrons.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <assert.h>
+#include <rmd160.h>
+#include <string.h>
+
+void
+test_rmd160(const char *digest, const char *string)
+{
+	char result[RMD160_DIGEST_STRING_LENGTH];
+
+	assert(strcmp(digest, RMD160Data(string, strlen(string), result)) == 0);
+}
+
+int
+main()
+{
+	test_rmd160("9c1185a5c5e9fc54612808977ee8f548b2258d31", "");
+	test_rmd160("8eb208f7e05d987a9b044a8e98c6b087f15a0bfc", "abc");
+	test_rmd160("e9cbd2ea8015a084ce9cf83a3c65b51f8fa10a39", "12345");
+
+	return 0;
+}
diff --git a/test/sha1.c b/test/sha1.c
new file mode 100644
index 0000000..426af01
--- /dev/null
+++ b/test/sha1.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2016 Guillem Jover <guillem@hadrons.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <assert.h>
+#include <sha1.h>
+#include <string.h>
+
+void
+test_sha1(const char *digest, const char *string)
+{
+	char result[SHA1_DIGEST_STRING_LENGTH];
+
+	assert(strcmp(digest, SHA1Data(string, strlen(string), result)) == 0);
+}
+
+int
+main()
+{
+	test_sha1("da39a3ee5e6b4b0d3255bfef95601890afd80709", "");
+	test_sha1("a9993e364706816aba3e25717850c26c9cd0d89d", "abc");
+	test_sha1("8cb2237d0679ca88db6464eac60da96345513964", "12345");
+
+	return 0;
+}
diff --git a/test/sha2.c b/test/sha2.c
new file mode 100644
index 0000000..536dcb5
--- /dev/null
+++ b/test/sha2.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright © 2016 Guillem Jover <guillem@hadrons.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <assert.h>
+#include <sha2.h>
+#include <string.h>
+
+void
+test_sha256(const char *digest, const char *string)
+{
+	char result[SHA256_DIGEST_STRING_LENGTH];
+
+	assert(strcmp(digest, SHA256Data(string, strlen(string), result)) == 0);
+}
+
+void
+test_sha384(const char *digest, const char *string)
+{
+	char result[SHA384_DIGEST_STRING_LENGTH];
+
+	assert(strcmp(digest, SHA384Data(string, strlen(string), result)) == 0);
+}
+
+void
+test_sha512(const char *digest, const char *string)
+{
+	char result[SHA512_DIGEST_STRING_LENGTH];
+
+	assert(strcmp(digest, SHA512Data(string, strlen(string), result)) == 0);
+}
+
+int
+main()
+{
+	test_sha256("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
+	            "");
+	test_sha256("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
+	            "abc");
+	test_sha256("5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5",
+	            "12345");
+
+	test_sha384("38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b",
+	            "");
+	test_sha384("cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7",
+	            "abc");
+	test_sha384("0fa76955abfa9dafd83facca8343a92aa09497f98101086611b0bfa95dbc0dcc661d62e9568a5a032ba81960f3e55d4a",
+	            "12345");
+
+	test_sha512("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e",
+	            "");
+	test_sha512("ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f",
+	            "abc");
+	test_sha512("3627909a29c31381a071ec27f7c9ca97726182aed29a7ddd2e54353322cfb30abb9e3a6df2ac2c20fe23436311d678564d0c8d305930575f60e2d3d048184d79",
+	            "12345");
+
+	return 0;
+}