From b0b66be747fdb18388248fe34ba3b4a62e055c9e Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Tue, 22 Jun 2010 02:57:58 +1000 Subject: [PATCH] Added md2/1 support --- src/sha.erl | 6 +++++- src/tls/sha_drv.c | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/sha.erl b/src/sha.erl index 591ed6f30..64c15c166 100644 --- a/src/sha.erl +++ b/src/sha.erl @@ -27,7 +27,8 @@ -module(sha). -author('alexey@process-one.net'). --export([start/0, sha/1, sha1/1, sha224/1, sha256/1, sha384/1, sha512/1]). +-export([start/0, sha/1, sha1/1, sha224/1, sha256/1, sha384/1, + sha512/1, md2/1]). -include("ejabberd.hrl"). @@ -79,6 +80,9 @@ sha384(Text) -> sha512(Text) -> erlang:port_control(?DRIVER, 512, Text). +md2(Text) -> + erlang:port_control(?DRIVER, 2, Text). + driver_path() -> Suffix = case os:type() of {win32, _} -> ".dll"; diff --git a/src/tls/sha_drv.c b/src/tls/sha_drv.c index bfb101391..13d65803a 100644 --- a/src/tls/sha_drv.c +++ b/src/tls/sha_drv.c @@ -20,6 +20,7 @@ #include #include +#include static ErlDrvData sha_drv_start(ErlDrvPort port, char *buf) { @@ -35,6 +36,11 @@ static int sha_drv_control(ErlDrvData handle, ErlDrvBinary *b = NULL; switch (command) { + case 2: + rlen = MD2_DIGEST_LENGTH; + b = driver_alloc_binary(rlen); + if (b) MD2((unsigned char*)buf, len, (unsigned char*)b->orig_bytes); + break; case 224: rlen = SHA224_DIGEST_LENGTH; b = driver_alloc_binary(rlen);