r3637 - in branches/2.0/varnish-cache: include lib/libvarnish

tfheen at projects.linpro.no tfheen at projects.linpro.no
Fri Feb 6 10:48:41 CET 2009


Author: tfheen
Date: 2009-02-06 10:48:40 +0100 (Fri, 06 Feb 2009)
New Revision: 3637

Modified:
   branches/2.0/varnish-cache/include/vsha256.h
   branches/2.0/varnish-cache/lib/libvarnish/Makefile.am
   branches/2.0/varnish-cache/lib/libvarnish/vsha256.c
Log:
Merge r3436 + r3438: Hook SHA256 into the build

Hook SHA256 into the build

Neuter the FreeBSD specifics of SHA256 implementation.

In the end, it comes down to lack of POSIX definition of a way to find
out byte-endianess, sigh...



Modified: branches/2.0/varnish-cache/include/vsha256.h
===================================================================
--- branches/2.0/varnish-cache/include/vsha256.h	2009-02-06 09:29:17 UTC (rev 3636)
+++ branches/2.0/varnish-cache/include/vsha256.h	2009-02-06 09:48:40 UTC (rev 3637)
@@ -29,7 +29,7 @@
 #ifndef _SHA256_H_
 #define _SHA256_H_
 
-#include <sys/types.h>
+#include <stdint.h>
 
 typedef struct SHA256Context {
 	uint32_t state[8];
@@ -41,10 +41,6 @@
 void	SHA256_Init(SHA256_CTX *);
 void	SHA256_Update(SHA256_CTX *, const void *, size_t);
 void	SHA256_Final(unsigned char [32], SHA256_CTX *);
-char   *SHA256_End(SHA256_CTX *, char *);
-char   *SHA256_File(const char *, char *);
-char   *SHA256_FileChunk(const char *, char *, off_t, off_t);
-char   *SHA256_Data(const void *, unsigned int, char *);
 __END_DECLS
 
 #endif /* !_SHA256_H_ */

Modified: branches/2.0/varnish-cache/lib/libvarnish/Makefile.am
===================================================================
--- branches/2.0/varnish-cache/lib/libvarnish/Makefile.am	2009-02-06 09:29:17 UTC (rev 3636)
+++ branches/2.0/varnish-cache/lib/libvarnish/Makefile.am	2009-02-06 09:48:40 UTC (rev 3637)
@@ -24,6 +24,7 @@
 	vlu.c \
 	vpf.c \
 	vsb.c \
+	vsha256.c \
 	vss.c \
 	vtmpfile.c
 

Modified: branches/2.0/varnish-cache/lib/libvarnish/vsha256.c
===================================================================
--- branches/2.0/varnish-cache/lib/libvarnish/vsha256.c	2009-02-06 09:29:17 UTC (rev 3636)
+++ branches/2.0/varnish-cache/lib/libvarnish/vsha256.c	2009-02-06 09:48:40 UTC (rev 3637)
@@ -22,19 +22,17 @@
  * 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.
+ *
+ * From: $FreeBSD: head/lib/libmd/sha256c.c 154479 2006-01-17 15:35:57Z phk $
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libmd/sha256c.c 154479 2006-01-17 15:35:57Z phk $");
+#include <stdint.h>
 
-#include <sys/endian.h>
-#include <sys/types.h>
-
 #include <string.h>
 
 #include "vsha256.h"
 
-#if BYTE_ORDER == BIG_ENDIAN
+#if defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN
 
 /* Copy a vector of big-endian uint32_t into a vector of bytes */
 #define be32enc_vect(dst, src, len)	\
@@ -44,8 +42,27 @@
 #define be32dec_vect(dst, src, len)	\
 	memcpy((void *)dst, (const void *)src, (size_t)len)
 
-#else /* BYTE_ORDER != BIG_ENDIAN */
+#else /* BYTE_ORDER != BIG_ENDIAN or in doubt... */
 
+static __inline uint32_t
+mybe32dec(const void *pp)
+{
+        unsigned char const *p = (unsigned char const *)pp;
+
+        return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
+}
+
+static __inline void
+mybe32enc(void *pp, uint32_t u)
+{
+        unsigned char *p = (unsigned char *)pp;
+
+        p[0] = (u >> 24) & 0xff;
+        p[1] = (u >> 16) & 0xff;
+        p[2] = (u >> 8) & 0xff;
+        p[3] = u & 0xff;
+}
+
 /*
  * Encode a length len/4 vector of (uint32_t) into a length len vector of
  * (unsigned char) in big-endian form.  Assumes len is a multiple of 4.
@@ -56,7 +73,7 @@
 	size_t i;
 
 	for (i = 0; i < len / 4; i++)
-		be32enc(dst + i * 4, src[i]);
+		mybe32enc(dst + i * 4, src[i]);
 }
 
 /*
@@ -69,10 +86,10 @@
 	size_t i;
 
 	for (i = 0; i < len / 4; i++)
-		dst[i] = be32dec(src + i * 4);
+		dst[i] = mybe32dec(src + i * 4);
 }
 
-#endif /* BYTE_ORDER != BIG_ENDIAN */
+#endif 
 
 /* Elementary functions used by SHA256 */
 #define Ch(x, y, z)	((x & (y ^ z)) ^ z)



More information about the varnish-commit mailing list