LIBZPMSRC=sha256.c db.c compress.c uncompress.c zpm.c zpm_hash.c \
foreach_path.c vercmp.c findpkg.c quote.c dbquery.c script_hash.c \
parse.c integ.c seterror.c notes.c createpkg.c buffer.c \
- blake2/ref/blake2b-ref.o
+ blake2b.c
LIBZPMOBJ=$(addprefix lib/, $(LIBZPMSRC:%.c=%.o))
crypto/libeddsa/lib/sha512.c \
crypto/libeddsa/lib/x25519.c
-SIGNOBJ=$(SIGNSRC:.c=.o) lib/readpass.o lib/blake2/ref/blake2b-ref.o \
+SIGNOBJ=$(SIGNSRC:.c=.o) lib/readpass.o lib/blake2b.o \
crypto/chacha.o
$(SIGNOBJ): CFLAGS=-Wall -Wextra -W -Werror -Wno-pointer-sign \
#include "eddsa.h"
#include "sha512.h"
#include "crypto/chacha.h"
-#include "lib/blake2/ref/blake2.h"
+#include "lib/blake2.h"
char *readpass(char *prompt);
-/*
- BLAKE2 reference source code package - reference C implementations
-
- Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
- terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
- your option. The terms of these licenses can be found at:
-
- - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
- - OpenSSL license : https://www.openssl.org/source/license.html
- - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
-
- More information about the BLAKE2 hash function can be found at
- https://blake2.net.
-*/
#ifndef BLAKE2_H
#define BLAKE2_H
#define BLAKE2_PACKED(x) __pragma(pack(push, 1)) x __pragma(pack(pop))
#else
#define BLAKE2_PACKED(x) x __attribute__((packed))
-#endif
-
-#if defined(__cplusplus)
-extern "C" {
#endif
enum blake2s_constant
/* This is simply an alias for blake2b */
int blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
-#if defined(__cplusplus)
-}
-#endif
-
#endif
+++ /dev/null
-/*
- BLAKE2 reference source code package - reference C implementations
-
- Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
- terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
- your option. The terms of these licenses can be found at:
-
- - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
- - OpenSSL license : https://www.openssl.org/source/license.html
- - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
-
- More information about the BLAKE2 hash function can be found at
- https://blake2.net.
-*/
-#ifndef BLAKE2_IMPL_H
-#define BLAKE2_IMPL_H
-
-#include <stdint.h>
-#include <string.h>
-
-#if !defined(__cplusplus) && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L)
- #if defined(_MSC_VER)
- #define BLAKE2_INLINE __inline
- #elif defined(__GNUC__)
- #define BLAKE2_INLINE __inline__
- #else
- #define BLAKE2_INLINE
- #endif
-#else
- #define BLAKE2_INLINE inline
-#endif
-
-static BLAKE2_INLINE uint32_t load32( const void *src )
-{
-#if defined(NATIVE_LITTLE_ENDIAN)
- uint32_t w;
- memcpy(&w, src, sizeof w);
- return w;
-#else
- const uint8_t *p = ( const uint8_t * )src;
- return (( uint32_t )( p[0] ) << 0) |
- (( uint32_t )( p[1] ) << 8) |
- (( uint32_t )( p[2] ) << 16) |
- (( uint32_t )( p[3] ) << 24) ;
-#endif
-}
-
-static BLAKE2_INLINE uint64_t load64( const void *src )
-{
-#if defined(NATIVE_LITTLE_ENDIAN)
- uint64_t w;
- memcpy(&w, src, sizeof w);
- return w;
-#else
- const uint8_t *p = ( const uint8_t * )src;
- return (( uint64_t )( p[0] ) << 0) |
- (( uint64_t )( p[1] ) << 8) |
- (( uint64_t )( p[2] ) << 16) |
- (( uint64_t )( p[3] ) << 24) |
- (( uint64_t )( p[4] ) << 32) |
- (( uint64_t )( p[5] ) << 40) |
- (( uint64_t )( p[6] ) << 48) |
- (( uint64_t )( p[7] ) << 56) ;
-#endif
-}
-
-static BLAKE2_INLINE uint16_t load16( const void *src )
-{
-#if defined(NATIVE_LITTLE_ENDIAN)
- uint16_t w;
- memcpy(&w, src, sizeof w);
- return w;
-#else
- const uint8_t *p = ( const uint8_t * )src;
- return ( uint16_t )((( uint32_t )( p[0] ) << 0) |
- (( uint32_t )( p[1] ) << 8));
-#endif
-}
-
-static BLAKE2_INLINE void store16( void *dst, uint16_t w )
-{
-#if defined(NATIVE_LITTLE_ENDIAN)
- memcpy(dst, &w, sizeof w);
-#else
- uint8_t *p = ( uint8_t * )dst;
- *p++ = ( uint8_t )w; w >>= 8;
- *p++ = ( uint8_t )w;
-#endif
-}
-
-static BLAKE2_INLINE void store32( void *dst, uint32_t w )
-{
-#if defined(NATIVE_LITTLE_ENDIAN)
- memcpy(dst, &w, sizeof w);
-#else
- uint8_t *p = ( uint8_t * )dst;
- p[0] = (uint8_t)(w >> 0);
- p[1] = (uint8_t)(w >> 8);
- p[2] = (uint8_t)(w >> 16);
- p[3] = (uint8_t)(w >> 24);
-#endif
-}
-
-static BLAKE2_INLINE void store64( void *dst, uint64_t w )
-{
-#if defined(NATIVE_LITTLE_ENDIAN)
- memcpy(dst, &w, sizeof w);
-#else
- uint8_t *p = ( uint8_t * )dst;
- p[0] = (uint8_t)(w >> 0);
- p[1] = (uint8_t)(w >> 8);
- p[2] = (uint8_t)(w >> 16);
- p[3] = (uint8_t)(w >> 24);
- p[4] = (uint8_t)(w >> 32);
- p[5] = (uint8_t)(w >> 40);
- p[6] = (uint8_t)(w >> 48);
- p[7] = (uint8_t)(w >> 56);
-#endif
-}
-
-static BLAKE2_INLINE uint64_t load48( const void *src )
-{
- const uint8_t *p = ( const uint8_t * )src;
- return (( uint64_t )( p[0] ) << 0) |
- (( uint64_t )( p[1] ) << 8) |
- (( uint64_t )( p[2] ) << 16) |
- (( uint64_t )( p[3] ) << 24) |
- (( uint64_t )( p[4] ) << 32) |
- (( uint64_t )( p[5] ) << 40) ;
-}
-
-static BLAKE2_INLINE void store48( void *dst, uint64_t w )
-{
- uint8_t *p = ( uint8_t * )dst;
- p[0] = (uint8_t)(w >> 0);
- p[1] = (uint8_t)(w >> 8);
- p[2] = (uint8_t)(w >> 16);
- p[3] = (uint8_t)(w >> 24);
- p[4] = (uint8_t)(w >> 32);
- p[5] = (uint8_t)(w >> 40);
-}
-
-static BLAKE2_INLINE uint32_t rotr32( const uint32_t w, const unsigned c )
-{
- return ( w >> c ) | ( w << ( 32 - c ) );
-}
-
-static BLAKE2_INLINE uint64_t rotr64( const uint64_t w, const unsigned c )
-{
- return ( w >> c ) | ( w << ( 64 - c ) );
-}
-
-/* prevents compiler optimizing out memset() */
-static BLAKE2_INLINE void secure_zero_memory(void *v, size_t n)
-{
- static void *(*const volatile memset_v)(void *, int, size_t) = &memset;
- memset_v(v, 0, n);
-}
-
-#endif
/*
- BLAKE2 reference source code package - reference C implementations
-
- Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
- terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
- your option. The terms of these licenses can be found at:
-
- - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
- - OpenSSL license : https://www.openssl.org/source/license.html
- - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
-
- More information about the BLAKE2 hash function can be found at
- https://blake2.net.
-*/
+ * public domain blake2 implementation adapted from the reference
+ * implementation by Samuel Neves
+ * More information about the BLAKE2 hash function can be found at
+ * https://blake2.net.
+ */
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "blake2.h"
-#include "blake2-impl.h"
+
+static uint64_t load64( const void *src )
+{
+#if defined(NATIVE_LITTLE_ENDIAN)
+ uint64_t w;
+ memcpy(&w, src, sizeof w);
+ return w;
+#else
+ const uint8_t *p = ( const uint8_t * )src;
+ return (( uint64_t )( p[0] ) << 0) |
+ (( uint64_t )( p[1] ) << 8) |
+ (( uint64_t )( p[2] ) << 16) |
+ (( uint64_t )( p[3] ) << 24) |
+ (( uint64_t )( p[4] ) << 32) |
+ (( uint64_t )( p[5] ) << 40) |
+ (( uint64_t )( p[6] ) << 48) |
+ (( uint64_t )( p[7] ) << 56) ;
+#endif
+}
+
+static void store32( void *dst, uint32_t w )
+{
+#if defined(NATIVE_LITTLE_ENDIAN)
+ memcpy(dst, &w, sizeof w);
+#else
+ uint8_t *p = ( uint8_t * )dst;
+ p[0] = (uint8_t)(w >> 0);
+ p[1] = (uint8_t)(w >> 8);
+ p[2] = (uint8_t)(w >> 16);
+ p[3] = (uint8_t)(w >> 24);
+#endif
+}
+
+static void store64( void *dst, uint64_t w )
+{
+#if defined(NATIVE_LITTLE_ENDIAN)
+ memcpy(dst, &w, sizeof w);
+#else
+ uint8_t *p = ( uint8_t * )dst;
+ p[0] = (uint8_t)(w >> 0);
+ p[1] = (uint8_t)(w >> 8);
+ p[2] = (uint8_t)(w >> 16);
+ p[3] = (uint8_t)(w >> 24);
+ p[4] = (uint8_t)(w >> 32);
+ p[5] = (uint8_t)(w >> 40);
+ p[6] = (uint8_t)(w >> 48);
+ p[7] = (uint8_t)(w >> 56);
+#endif
+}
+
+static uint64_t rotr64( const uint64_t w, const unsigned c )
+{
+ return ( w >> c ) | ( w << ( 64 - c ) );
+}
+
+/* prevents compiler optimizing out memset() */
+static void secure_zero_memory(void *v, size_t n)
+{
+ static void *(*const volatile memset_v)(void *, int, size_t) = &memset;
+ memset_v(v, 0, n);
+}
static const uint64_t blake2b_IV[8] =
{
}
/* Some helper functions, not necessarily useful */
-static int blake2b_is_lastblock( const blake2b_state *S )
-{
- return S->f[0] != 0;
+static int blake2b_is_lastblock( const blake2b_state *S ) {
+ return S->f[0] != 0;
}
static void blake2b_set_lastblock( blake2b_state *S )
int blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) {
return blake2b(out, outlen, in, inlen, key, keylen);
}
-
-#if defined(SUPERCOP)
-int crypto_hash( unsigned char *out, unsigned char *in, unsigned long long inlen )
-{
- return blake2b( out, BLAKE2B_OUTBYTES, in, inlen, NULL, 0 );
-}
-#endif
-
-#if defined(BLAKE2B_SELFTEST)
-#include <string.h>
-#include "blake2-kat.h"
-int main( void )
-{
- uint8_t key[BLAKE2B_KEYBYTES];
- uint8_t buf[BLAKE2_KAT_LENGTH];
- size_t i, step;
-
- for( i = 0; i < BLAKE2B_KEYBYTES; ++i )
- key[i] = ( uint8_t )i;
-
- for( i = 0; i < BLAKE2_KAT_LENGTH; ++i )
- buf[i] = ( uint8_t )i;
-
- /* Test simple API */
- for( i = 0; i < BLAKE2_KAT_LENGTH; ++i )
- {
- uint8_t hash[BLAKE2B_OUTBYTES];
- blake2b( hash, BLAKE2B_OUTBYTES, buf, i, key, BLAKE2B_KEYBYTES );
-
- if( 0 != memcmp( hash, blake2b_keyed_kat[i], BLAKE2B_OUTBYTES ) )
- {
- goto fail;
- }
- }
-
- /* Test streaming API */
- for(step = 1; step < BLAKE2B_BLOCKBYTES; ++step) {
- for (i = 0; i < BLAKE2_KAT_LENGTH; ++i) {
- uint8_t hash[BLAKE2B_OUTBYTES];
- blake2b_state S;
- uint8_t * p = buf;
- size_t mlen = i;
- int err = 0;
-
- if( (err = blake2b_init_key(&S, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES)) < 0 ) {
- goto fail;
- }
-
- while (mlen >= step) {
- if ( (err = blake2b_update(&S, p, step)) < 0 ) {
- goto fail;
- }
- mlen -= step;
- p += step;
- }
- if ( (err = blake2b_update(&S, p, mlen)) < 0) {
- goto fail;
- }
- if ( (err = blake2b_final(&S, hash, BLAKE2B_OUTBYTES)) < 0) {
- goto fail;
- }
-
- if (0 != memcmp(hash, blake2b_keyed_kat[i], BLAKE2B_OUTBYTES)) {
- goto fail;
- }
- }
- }
-
- puts( "ok" );
- return 0;
-fail:
- puts("error");
- return -1;
-}
-#endif
#include "zpm.h"
#include "sqlite3.h"
-#include "lib/blake2/ref/blake2.h"
+#include "blake2.h"
static void hash_byte(struct blake2b_state__ *h, int ch) {
unsigned char buf[1];
#include "zpm.h"
#include "elf.h"
-#include "lib/blake2/ref/blake2.h"
+#include "blake2.h"
int zpm_hash_mem(void *mem, size_t size, char *hash) {
struct blake2b_state__ blake;
#include "zpm.h"
#include "sha256.h"
-#include "lib/blake2/ref/blake2.h"
+#include "blake2.h"
static int hash_file(int fd, char *hash) {
unsigned char buf[4096];