aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2010-12-26 11:13:37 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2010-12-26 11:13:37 -0500
commitbc7000ce141d30e4db4842edd8fa067ac1ec191d (patch)
treed59424249e21ce243abae8ec042deb0fdeccb3d7 /src
parenta090c56aad2934d397d23df2a7b17156b12695a1 (diff)
Switch from libmhash to OpenSSL
Diffstat (limited to 'src')
-rw-r--r--src/c/Makefile.am4
-rw-r--r--src/c/Makefile.in21
-rw-r--r--src/c/openssl.c (renamed from src/c/mhash.c)42
-rw-r--r--src/compiler.sml10
-rw-r--r--src/config.sig2
-rw-r--r--src/config.sml.in2
6 files changed, 36 insertions, 45 deletions
diff --git a/src/c/Makefile.am b/src/c/Makefile.am
index 91b48df5..613c2452 100644
--- a/src/c/Makefile.am
+++ b/src/c/Makefile.am
@@ -1,9 +1,9 @@
lib_LTLIBRARIES = liburweb.la liburweb_http.la liburweb_cgi.la liburweb_fastcgi.la
-liburweb_la_SOURCES = memmem.c mhash.c urweb.c request.c queue.c
+liburweb_la_SOURCES = memmem.c openssl.c urweb.c request.c queue.c
liburweb_http_la_SOURCES = http.c
liburweb_cgi_la_SOURCES = cgi.c
liburweb_fastcgi_la_SOURCES = fastcgi.c
-AM_CPPFLAGS = -I../../include
+AM_CPPFLAGS = -I../../include @OPENSSL_INCLUDES@
AM_CFLAGS = -Wimplicit -Wall -Werror
diff --git a/src/c/Makefile.in b/src/c/Makefile.in
index afbd033e..a3684165 100644
--- a/src/c/Makefile.in
+++ b/src/c/Makefile.in
@@ -37,10 +37,10 @@ host_triplet = @host@
subdir = src/c
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
- $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
- $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
- $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_openssl.m4 \
+ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
+ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+ $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
@@ -71,7 +71,7 @@ am__base_list = \
am__installdirs = "$(DESTDIR)$(libdir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
liburweb_la_LIBADD =
-am_liburweb_la_OBJECTS = memmem.lo mhash.lo urweb.lo request.lo \
+am_liburweb_la_OBJECTS = memmem.lo openssl.lo urweb.lo request.lo \
queue.lo
liburweb_la_OBJECTS = $(am_liburweb_la_OBJECTS)
liburweb_cgi_la_LIBADD =
@@ -145,7 +145,6 @@ LIPO = @LIPO@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
-MHASH_LIB_DIR = @MHASH_LIB_DIR@
MKDIR_P = @MKDIR_P@
MLLEX = @MLLEX@
MLTON = @MLTON@
@@ -154,6 +153,9 @@ NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
+OPENSSL_INCLUDES = @OPENSSL_INCLUDES@
+OPENSSL_LDFLAGS = @OPENSSL_LDFLAGS@
+OPENSSL_LIBS = @OPENSSL_LIBS@
OTOOL = @OTOOL@
OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
@@ -164,6 +166,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
@@ -224,11 +227,11 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
lib_LTLIBRARIES = liburweb.la liburweb_http.la liburweb_cgi.la liburweb_fastcgi.la
-liburweb_la_SOURCES = memmem.c mhash.c urweb.c request.c queue.c
+liburweb_la_SOURCES = memmem.c openssl.c urweb.c request.c queue.c
liburweb_http_la_SOURCES = http.c
liburweb_cgi_la_SOURCES = cgi.c
liburweb_fastcgi_la_SOURCES = fastcgi.c
-AM_CPPFLAGS = -I../../include
+AM_CPPFLAGS = -I../../include @OPENSSL_INCLUDES@
AM_CFLAGS = -Wimplicit -Wall -Werror
all: all-am
@@ -314,7 +317,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fastcgi.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/http.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memmem.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mhash.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openssl.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/queue.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/request.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/urweb.Plo@am__quote@
diff --git a/src/c/mhash.c b/src/c/openssl.c
index 069eff2a..6a998e29 100644
--- a/src/c/mhash.c
+++ b/src/c/openssl.c
@@ -1,19 +1,20 @@
#include "config.h"
-#include <mhash.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
-#define KEYSIZE 16
-#define PASSSIZE 4
+#include <openssl/sha.h>
-#define HASH_ALGORITHM MHASH_SHA256
-#define HASH_BLOCKSIZE 32
-#define KEYGEN_ALGORITHM KEYGEN_MCRYPT
+#define PASSSIZE 4
-int uw_hash_blocksize = HASH_BLOCKSIZE;
+int uw_hash_blocksize = 32;
static int password[PASSSIZE];
-static unsigned char private_key[KEYSIZE];
char *uw_sig_file = NULL;
@@ -25,10 +26,6 @@ static void random_password() {
}
void uw_init_crypto() {
- KEYGEN kg = {{HASH_ALGORITHM, HASH_ALGORITHM}};
-
- assert(mhash_get_block_size(HASH_ALGORITHM) == HASH_BLOCKSIZE);
-
if (uw_sig_file) {
int fd;
@@ -63,22 +60,13 @@ void uw_init_crypto() {
}
} else
random_password();
-
- if (mhash_keygen_ext(KEYGEN_ALGORITHM, kg,
- private_key, sizeof(private_key),
- (unsigned char*)password, sizeof(password)) < 0) {
- fprintf(stderr, "Key generation failed\n");
- exit(1);
- }
}
-void uw_sign(const char *in, char *out) {
- MHASH td;
+void uw_sign(const char *in, unsigned char *out) {
+ SHA256_CTX c;
- td = mhash_hmac_init(HASH_ALGORITHM, private_key, sizeof(private_key),
- mhash_get_hash_pblock(HASH_ALGORITHM));
-
- mhash(td, in, strlen(in));
- if (mhash_hmac_deinit(td, out) < 0)
- fprintf(stderr, "Signing failed\n");
+ SHA256_Init(&c);
+ SHA256_Update(&c, password, sizeof password);
+ SHA256_Update(&c, in, strlen(in));
+ SHA256_Final(out, &c);
}
diff --git a/src/compiler.sml b/src/compiler.sml
index 0c0a527f..0668ac42 100644
--- a/src/compiler.sml
+++ b/src/compiler.sml
@@ -1285,16 +1285,16 @@ fun compileC {cname, oname, ename, libs, profile, debug, link = link'} =
let
val proto = Settings.currentProtocol ()
- val (lib, mhash) = if Settings.getStaticLinking () then
- (#linkStatic proto ^ " " ^ Config.lib ^ "/../liburweb.a", Config.libMhash ^ "/libmhash.a")
- else
- ("-L" ^ Config.lib ^ "/.. -lurweb " ^ #linkDynamic proto, "-L" ^ Config.libMhash ^ " -lmhash")
+ val lib = if Settings.getStaticLinking () then
+ #linkStatic proto ^ " " ^ Config.lib ^ "/../liburweb.a"
+ else
+ "-L" ^ Config.lib ^ "/.. -lurweb " ^ #linkDynamic proto
val compile = "gcc " ^ Config.gccArgs ^ " -Wimplicit -Werror -O3 -fno-inline -I " ^ Config.includ
^ " " ^ #compile proto
^ " -c " ^ cname ^ " -o " ^ oname
- val link = "gcc -Werror -O3 -lm -lcrypt -pthread " ^ Config.gccArgs ^ " " ^ libs ^ " " ^ lib ^ " " ^ mhash ^ " " ^ oname
+ val link = "gcc -Werror -O3 -lm -lcrypt -pthread " ^ Config.gccArgs ^ " " ^ libs ^ " " ^ lib ^ " " ^ Config.openssl ^ " " ^ oname
^ " -o " ^ ename
val (compile, link) =
diff --git a/src/config.sig b/src/config.sig
index 0e8a03c5..6afd9910 100644
--- a/src/config.sig
+++ b/src/config.sig
@@ -9,5 +9,5 @@ signature CONFIG = sig
val libJs : string
val gccArgs : string
- val libMhash : string
+ val openssl : string
end
diff --git a/src/config.sml.in b/src/config.sml.in
index 24ef2ca2..bb76ea73 100644
--- a/src/config.sml.in
+++ b/src/config.sml.in
@@ -13,6 +13,6 @@ val libJs = OS.Path.joinDirFile {dir = lib,
file = "js"}
val gccArgs = "@GCCARGS@"
-val libMhash = "@MHASH_LIB_DIR@"
+val openssl = "@OPENSSL_LDFLAGS@ @OPENSSL_LIBS@"
end