From: David Scott Date: Mon, 26 Oct 2009 16:32:15 +0000 (+0000) Subject: [refactoring] remove unused sha1 library (the one we use is in stdext) X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=59a66c102b98d3697afd57c21f78a1592100a4cc;p=xcp%2Fxen-api-libs.git [refactoring] remove unused sha1 library (the one we use is in stdext) Signed-off-by: Thomas Gazagnaire --- diff --git a/sha1/META.in b/sha1/META.in deleted file mode 100644 index a48e46e..0000000 --- a/sha1/META.in +++ /dev/null @@ -1,4 +0,0 @@ -version = "@VERSION@" -description = "Sha1 hash functions" -archive(byte) = "sha1.cma" -archive(native) = "sha1.cmxa" diff --git a/sha1/Makefile b/sha1/Makefile deleted file mode 100644 index 9732c48..0000000 --- a/sha1/Makefile +++ /dev/null @@ -1,69 +0,0 @@ -CC = gcc -CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml -I$(XEN_ROOT)/usr/include -I../mmap -I./ -OCAMLC = ocamlc -g -OCAMLOPT = ocamlopt -OCAMLOPTFLAGS = -g -dtypes -I ./ - -LDFLAGS = -cclib -L./ - -DESTDIR ?= / -VERSION := $(shell hg parents --template "{rev}" 2>/dev/null || echo 0.0) - -OCAMLABI := $(shell ocamlc -version) -OCAMLLIBDIR := $(shell ocamlc -where) -OCAMLDESTDIR ?= $(OCAMLLIBDIR) - -OBJS = sha1 -INTF = sha1.cmi -LIBS = sha1.cma sha1.cmxa - -PROGRAMS = - -all: $(INTF) $(LIBS) $(PROGRAMS) - -bins: $(PROGRAMS) - -libs: $(LIBS) - -sha1.cmxa: libsha1_stubs.a $(foreach obj,$(OBJS),$(obj).cmx) - $(OCAMLOPT) $(OCAMLOPTFLAGS) -a -o $@ -cclib -lsha1_stubs $(foreach obj,$(OBJS),$(obj).cmx) - -sha1.cma: $(foreach obj,$(OBJS),$(obj).cmo) - $(OCAMLC) -a -dllib dllsha1_stubs.so -cclib -lsha1_stubs -o $@ $(foreach obj,$(OBJS),$(obj).cmo) - -sha1_stubs.a: sha1_stubs.o - ocamlmklib -o sha1_stubs $+ - -libsha1_stubs.a: sha1_stubs.o - ar rcs $@ $+ - ocamlmklib -o sha1_stubs $+ - -%.cmo: %.ml - $(OCAMLC) -c -o $@ $< - -%.cmi: %.mli - $(OCAMLC) -c -o $@ $< - -%.mli: %.ml - $(OCAMLC) -i $< > $@ - -%.cmx: %.ml - $(OCAMLOPT) $(OCAMLOPTFLAGS) -c -o $@ $< - -%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - -META: META.in - sed 's/@VERSION@/$(VERSION)/g' < $< > $@ - -.PHONY: install -install: $(LIBS) META - ocamlfind install -destdir $(DESTDIR)$(shell ocamlfind printconf destdir) -ldconf ignore sha1 META $(INTF) $(LIBS) *.a *.so *.cmx - -.PHONY: uninstall -uninstall: - ocamlfind remove sha1 - -clean: - rm -f *.o *.so *.a *.cmo *.cmi *.cma *.cmx *.cmxa *.annot $(LIBS) $(PROGRAMS) $(INTF) - diff --git a/sha1/sha1.ml b/sha1/sha1.ml deleted file mode 100644 index 13722c6..0000000 --- a/sha1/sha1.ml +++ /dev/null @@ -1,21 +0,0 @@ -(* - * Copyright (C) 2006-2009 Citrix Systems Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; version 2.1 only. with the special - * exception on linking described in file LICENSE. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - *) - -type ctx -type t - -external init: unit -> ctx = "stub_sha1_init" -external update: ctx -> string -> int -> int -> unit = "stub_sha1_update" -external finalize: ctx -> t = "stub_sha1_finalize" -external to_hex: t -> string = "stub_sha1_to_hex" diff --git a/sha1/sha1_stubs.c b/sha1/sha1_stubs.c deleted file mode 100644 index 403df5b..0000000 --- a/sha1/sha1_stubs.c +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (C) 2006-2009 Citrix Systems Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; version 2.1 only. with the special - * exception on linking described in file LICENSE. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - */ - -#include -#include -#include - -#include - -#ifdef WORDS_BIGENDIAN -#define be16_to_cpu(x) (x) -#define be32_to_cpu(x) (x) -#define be64_to_cpu(x) (x) -#define le16_to_cpu(x) bswap_16(x) -#define le32_to_cpu(x) bswap_32(x) -#define le64_to_cpu(x) bswap_64(x) -#else -#define be16_to_cpu(x) bswap_16(x) -#define be32_to_cpu(x) bswap_32(x) -#define be64_to_cpu(x) bswap_64(x) -#define le16_to_cpu(x) (x) -#define le32_to_cpu(x) (x) -#define le64_to_cpu(x) (x) -#endif - -struct sha1_ctx -{ - unsigned int state[5]; - unsigned char buf[64]; - unsigned long long count; -}; - -typedef struct { unsigned int digest[5]; } sha1_digest; - -static void sha1_init(struct sha1_ctx *ctx) -{ - memset(ctx, 0, sizeof(*ctx)); - - /* initialize H */ - ctx->state[0] = 0x67452301; - ctx->state[1] = 0xEFCDAB89; - ctx->state[2] = 0x98BADCFE; - ctx->state[3] = 0x10325476; - ctx->state[4] = 0xC3D2E1F0; -} - -#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) - -/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ -#define blk0(i) (block[i] = be32_to_cpu(((unsigned int*)buffer)[i])) -#define blk(i) (block[i] = rol(block[i-3]^block[i-8]^block[i-14]^block[i-16],1)) - -#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y) +blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); -#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y) +blk (i)+0x5A827999+rol(v,5);w=rol(w,30); -#define R2(v,w,x,y,z,i) z+=( w^x ^y) +blk (i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); -#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk (i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); -#define R4(v,w,x,y,z,i) z+=( w^x ^y) +blk (i)+0xCA62C1D6+rol(v,5);w=rol(w,30); - - -static void sha1_transform(unsigned int state[5], unsigned char buffer[64]) -{ - unsigned int block[80]; - unsigned int i, a, b, c, d, e; - - a = state[0]; - b = state[1]; - c = state[2]; - d = state[3]; - e = state[4]; - - for (i = 0; i < 15; i += 5) { - R0(a, b, c, d, e, 0 + i); - R0(e, a, b, c, d, 1 + i); - R0(d, e, a, b, c, 2 + i); - R0(c, d, e, a, b, 3 + i); - R0(b, c, d, e, a, 4 + i); - } - - R0(a, b, c, d, e, 15); - R1(e, a, b, c, d, 16); - R1(d, e, a, b, c, 17); - R1(c, d, e, a, b, 18); - R1(b, c, d, e, a, 19); - - for (i = 20; i < 40; i += 5) { - R2(a, b, c, d, e, 0 + i); - R2(e, a, b, c, d, 1 + i); - R2(d, e, a, b, c, 2 + i); - R2(c, d, e, a, b, 3 + i); - R2(b, c, d, e, a, 4 + i); - } - for (; i < 60; i += 5) { - R3(a, b, c, d, e, 0 + i); - R3(e, a, b, c, d, 1 + i); - R3(d, e, a, b, c, 2 + i); - R3(c, d, e, a, b, 3 + i); - R3(b, c, d, e, a, 4 + i); - } - for (; i < 80; i += 5) { - R4(a, b, c, d, e, 0 + i); - R4(e, a, b, c, d, 1 + i); - R4(d, e, a, b, c, 2 + i); - R4(c, d, e, a, b, 3 + i); - R4(b, c, d, e, a, 4 + i); - } - - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - state[4] += e; -} - -static void sha1_update(struct sha1_ctx *ctx, unsigned char *data, int len) -{ - unsigned int i, j; - j = ctx->count & 63; - ctx->count += len; - - if ((j + len) > 63) { - i = 64 - j; - memcpy(&ctx->buf[j], data, i); - sha1_transform(ctx->state, ctx->buf); - for ( ; i + 63 < len; i += 64) { - sha1_transform(ctx->state, &data[i]); - } - j = 0; - } else - i = 0; - memcpy(&ctx->buf[j], &data[i], len - i); -} - -static void sha1_finalize(struct sha1_ctx *ctx, sha1_digest *digest) -{ - int i; - unsigned long long finalcount = be64_to_cpu(ctx->count << 3); - - sha1_update(ctx, (unsigned char *)"\200", 1); - while ((ctx->count & 63) != 56) - sha1_update(ctx, (unsigned char *) "", 1); - - sha1_update(ctx, (unsigned char *) &finalcount, 8); - for (i = 0; i < 5; i++) - digest->digest[i] = be32_to_cpu(ctx->state[i]); -} - -static inline void sha1_to_hex(sha1_digest *digest, char *out) -{ - char *p; - int i; - for (p = out, i = 0; i < 20; i++, p += 2) - snprintf(p, 3, "%02x", ((unsigned char *) digest->digest)[i]); -} - -#define CAML_NAME_SPACE -#include -#include -#include -#include - -#define GET_CTX_STRUCT(a) ((struct sha1_ctx *) a) - -CAMLprim value stub_sha1_init(value unit) -{ - CAMLparam1(unit); - CAMLlocal1(result); - - result = caml_alloc(sizeof(struct sha1_ctx), Abstract_tag); - sha1_init(GET_CTX_STRUCT(result)); - - CAMLreturn(result); -} - -CAMLprim value stub_sha1_update(value ctx, value data, value ofs, value len) -{ - CAMLparam4(ctx, data, ofs, len); - sha1_update(GET_CTX_STRUCT(ctx), (unsigned char *) data + Int_val(ofs), - Int_val(len)); - CAMLreturn(Val_unit); -} - -CAMLprim value stub_sha1_finalize(value ctx) -{ - CAMLparam1(ctx); - CAMLlocal1(t); - - t = caml_alloc(sizeof(sha1_digest), Abstract_tag); - sha1_finalize(GET_CTX_STRUCT(ctx), (sha1_digest *) t); - - CAMLreturn(t); -} - -CAMLprim value stub_sha1_to_hex(value t) -{ - CAMLparam1(t); - CAMLlocal1(result); - - result = caml_alloc_string(40); - sha1_to_hex((sha1_digest *) t, String_val(result)); - - CAMLreturn(result); -} - -/* - * Local variables: - * indent-tabs-mode: t - * c-basic-offset: 8 - * tab-width: 8 - * End: - */ diff --git a/sha1/sha1sum.ml b/sha1/sha1sum.ml deleted file mode 100644 index 8c0db51..0000000 --- a/sha1/sha1sum.ml +++ /dev/null @@ -1,39 +0,0 @@ -(* - * Copyright (C) 2006-2009 Citrix Systems Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; version 2.1 only. with the special - * exception on linking described in file LICENSE. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - *) -let channel chan len = - let ctx = Sha1.init () - and buf = String.create 4096 in - - let left = ref len and eof = ref false in - while (!left == -1 || !left > 0) && not !eof - do - let len = if !left < 0 then 4096 else (min !left 4096) in - let readed = Pervasives.input chan buf 0 len in - if readed = 0 then - eof := true - else ( - Sha1.update ctx buf 0 readed; - if !left <> -1 then left := !left - readed - ) - done; - if !left > 0 && !eof then - raise End_of_file; - Sha1.finalize ctx - -let _ = - let name = Sys.argv.(1) in - let chan = open_in_bin name in - let digest = channel chan (-1) in - close_in chan; - Printf.printf "%s\n" (Sha1.to_hex digest)