Bug#663180: Patch fix
Source: ocaml-sha
Version: 1.7-2
Followup-For: Bug #663180
Hi again,
I unfortunately attached the wrong patch in my last mail. Here is the
real one.
MfG
Goswin
-- System Information:
Debian Release: wheezy/sid
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)
Kernel: Linux 3.1.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=C, LC_CTYPE=de_DE (charmap=ISO-8859-1)
Shell: /bin/sh linked to /bin/dash
Description: zero value patch
This patch adds a zero value (digest with all bits 0) to each of the
Sha modules. This can be used as placeholder or invalid digest in
situations where the proper digest can not be computed yet.
.
Technically a digest with all bits 0 is valid but the chance of it
actually occuring is remote. Still, the value should be compared using
physical equality.
.
TODO: should there be a 'val is_zero : t -> bool'?
Author: Goswin von Brederlow <goswin-v-b@web.de>
Last-Update: <2012-03-09>
---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:
Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Index: ocaml-sha-1.7/sha1_stubs.c
===================================================================
--- ocaml-sha-1.7.orig/sha1_stubs.c 2012-03-09 07:37:06.000000000 +0100
+++ ocaml-sha-1.7/sha1_stubs.c 2012-03-09 07:52:19.000000000 +0100
@@ -15,6 +15,7 @@
#include <unistd.h>
#include <fcntl.h>
+#include <string.h>
#include "sha1.h"
static inline int sha1_file(char *filename, sha1_digest *digest)
@@ -111,3 +112,14 @@
CAMLreturn(result);
}
+
+CAMLprim value stub_sha1_zero(void)
+{
+ CAMLparam0();
+ CAMLlocal1(zero);
+
+ zero = caml_alloc(sizeof(sha1_digest), Abstract_tag);
+ memset((void*)zero, 0, sizeof(sha1_digest));
+
+ CAMLreturn(zero);
+}
Index: ocaml-sha-1.7/sha1.mli
===================================================================
--- ocaml-sha-1.7.orig/sha1.mli 2012-03-09 07:37:06.000000000 +0100
+++ ocaml-sha-1.7/sha1.mli 2012-03-09 07:37:10.000000000 +0100
@@ -17,6 +17,9 @@
(** digest type - opaque *)
type t
+(** The zero digest *)
+val zero : t
+
(** Return the digest of the given string. *)
val string : string -> t
Index: ocaml-sha-1.7/sha1.ml
===================================================================
--- ocaml-sha-1.7.orig/sha1.ml 2012-03-09 07:37:06.000000000 +0100
+++ ocaml-sha-1.7/sha1.ml 2012-03-09 07:37:10.000000000 +0100
@@ -22,6 +22,9 @@
external to_bin: t -> string = "stub_sha1_to_bin"
external to_hex: t -> string = "stub_sha1_to_hex"
external file_fast: string -> t = "stub_sha1_file"
+external sha1_zero : unit -> t = "stub_sha1_zero"
+
+let zero = sha1_zero ()
let blksize = 4096
Index: ocaml-sha-1.7/sha512.mli
===================================================================
--- ocaml-sha-1.7.orig/sha512.mli 2012-03-09 07:37:05.000000000 +0100
+++ ocaml-sha-1.7/sha512.mli 2012-03-09 07:37:10.000000000 +0100
@@ -17,6 +17,9 @@
(** digest type - opaque *)
type t
+(** The zero digest *)
+val zero : t
+
(** Return the digest of the given string. *)
val string : string -> t
Index: ocaml-sha-1.7/sha256.ml
===================================================================
--- ocaml-sha-1.7.orig/sha256.ml 2012-03-09 07:37:06.000000000 +0100
+++ ocaml-sha-1.7/sha256.ml 2012-03-09 07:54:18.000000000 +0100
@@ -22,6 +22,9 @@
external to_bin: t -> string = "stub_sha256_to_bin"
external to_hex: t -> string = "stub_sha256_to_hex"
external file_fast: string -> t = "stub_sha256_file"
+external sha256_zero : unit -> t = "stub_sha256_zero"
+
+let zero = sha256_zero ()
let blksize = 4096
Index: ocaml-sha-1.7/sha256_stubs.c
===================================================================
--- ocaml-sha-1.7.orig/sha256_stubs.c 2012-03-09 07:37:06.000000000 +0100
+++ ocaml-sha-1.7/sha256_stubs.c 2012-03-09 07:53:22.000000000 +0100
@@ -15,6 +15,7 @@
#include <unistd.h>
#include <fcntl.h>
+#include <string.h>
#include "sha256.h"
static inline int sha256_file(char *filename, sha256_digest *digest)
@@ -110,3 +111,14 @@
CAMLreturn(result);
}
+
+CAMLprim value stub_sha256_zero(void)
+{
+ CAMLparam0();
+ CAMLlocal1(zero);
+
+ zero = caml_alloc(sizeof(sha256_digest), Abstract_tag);
+ memset((void*)zero, 0, sizeof(sha256_digest));
+
+ CAMLreturn(zero);
+}
Index: ocaml-sha-1.7/sha512.ml
===================================================================
--- ocaml-sha-1.7.orig/sha512.ml 2012-03-09 07:37:06.000000000 +0100
+++ ocaml-sha-1.7/sha512.ml 2012-03-09 07:54:26.000000000 +0100
@@ -22,6 +22,9 @@
external to_bin: t -> string = "stub_sha512_to_bin"
external to_hex: t -> string = "stub_sha512_to_hex"
external file_fast: string -> t = "stub_sha512_file"
+external sha512_zero : unit -> t = "stub_sha512_zero"
+
+let zero = sha512_zero ()
let blksize = 4096
Index: ocaml-sha-1.7/sha512_stubs.c
===================================================================
--- ocaml-sha-1.7.orig/sha512_stubs.c 2012-03-09 07:37:06.000000000 +0100
+++ ocaml-sha-1.7/sha512_stubs.c 2012-03-09 07:53:40.000000000 +0100
@@ -15,6 +15,7 @@
#include <unistd.h>
#include <fcntl.h>
+#include <string.h>
#include "sha512.h"
static inline int sha512_file(char *filename, sha512_digest *digest)
@@ -110,3 +111,14 @@
CAMLreturn(result);
}
+
+CAMLprim value stub_sha512_zero(void)
+{
+ CAMLparam0();
+ CAMLlocal1(zero);
+
+ zero = caml_alloc(sizeof(sha512_digest), Abstract_tag);
+ memset((void*)zero, 0, sizeof(sha512_digest));
+
+ CAMLreturn(zero);
+}
Index: ocaml-sha-1.7/sha256.mli
===================================================================
--- ocaml-sha-1.7.orig/sha256.mli 2012-03-09 07:37:06.000000000 +0100
+++ ocaml-sha-1.7/sha256.mli 2012-03-09 07:37:10.000000000 +0100
@@ -17,6 +17,9 @@
(** digest type - opaque *)
type t
+(** The zero digest *)
+val zero : t
+
(** Return the digest of the given string. *)
val string : string -> t
Reply to: