Commit 45902740 authored by Bernhard Link's avatar Bernhard Link

Add support for sha256

parent 020b0af6
2008-05-17 Bernhard R. Link <brlink@debian.org>
* Add support for sha256.
2008-05-16 Bernhard R. Link <brlink@debian.org>
* When include'ing a .changes file with Checksums
header and limiting to some files with -A or -T, do
......
......@@ -18,12 +18,12 @@ AM_CPPFLAGS = -std=gnu99 -Wall $(ARCHIVECPP) $(DBCPPFLAGS)
reprepro_LDADD = $(ARCHIVELIBS) $(DBLIBS)
changestool_LDADD = $(ARCHIVELIBS)
reprepro_SOURCES = copypackages.c readcompressed.c sourceextraction.c checksums.c readtextfile.c filecntl.c sha1.c configparser.c database.c freespace.c log.c changes.c incoming.c uploaderslist.c guesscomponent.c files.c md5.c dirs.c chunks.c reference.c binaries.c sources.c checks.c names.c dpkgversions.c release.c mprintf.c updates.c strlist.c signature.c distribution.c checkindeb.c checkindsc.c checkin.c upgradelist.c target.c aptmethod.c downloadcache.c main.c override.c terms.c ignore.c filterlist.c exports.c tracking.c optionsfile.c readrelease.c donefile.c pull.c contents.c filelist.c $(ARCHIVE_USED) $(ARCHIVE_CONTENTS)
reprepro_SOURCES = copypackages.c readcompressed.c sourceextraction.c checksums.c readtextfile.c filecntl.c sha1.c sha256.c configparser.c database.c freespace.c log.c changes.c incoming.c uploaderslist.c guesscomponent.c files.c md5.c dirs.c chunks.c reference.c binaries.c sources.c checks.c names.c dpkgversions.c release.c mprintf.c updates.c strlist.c signature.c distribution.c checkindeb.c checkindsc.c checkin.c upgradelist.c target.c aptmethod.c downloadcache.c main.c override.c terms.c ignore.c filterlist.c exports.c tracking.c optionsfile.c readrelease.c donefile.c pull.c contents.c filelist.c $(ARCHIVE_USED) $(ARCHIVE_CONTENTS)
EXTRA_reprepro_SOURCE = $(ARCHIVE_UNUSED)
changestool_SOURCES = readcompressed.c sourceextraction.c readtextfile.c filecntl.c tool.c chunkedit.c strlist.c checksums.c sha1.c md5.c mprintf.c chunks.c signature.c dirs.c names.c $(ARCHIVE_USED)
changestool_SOURCES = readcompressed.c sourceextraction.c readtextfile.c filecntl.c tool.c chunkedit.c strlist.c checksums.c sha1.c sha256.c md5.c mprintf.c chunks.c signature.c dirs.c names.c $(ARCHIVE_USED)
noinst_HEADERS = copypackages.h readcompressed.h sourceextraction.h checksums.h readtextfile.h filecntl.h sha1.h configparser.h database_p.h database.h freespace.h log.h changes.h incoming.h guesscomponent.h md5.h dirs.h files.h chunks.h reference.h binaries.h sources.h checks.h names.h release.h error.h mprintf.h updates.h strlist.h signature.h distribution.h debfile.h checkindeb.h checkindsc.h upgradelist.h target.h aptmethod.h downloadcache.h override.h terms.h ignore.h filterlist.h dpkgversions.h checkin.h exports.h globals.h tracking.h trackingt.h optionsfile.h readrelease.h donefile.h pull.h ar.h filelist.h contents.h chunkedit.h uploaderslist.h
noinst_HEADERS = copypackages.h readcompressed.h sourceextraction.h checksums.h readtextfile.h filecntl.h sha1.h sha256.h configparser.h database_p.h database.h freespace.h log.h changes.h incoming.h guesscomponent.h md5.h dirs.h files.h chunks.h reference.h binaries.h sources.h checks.h names.h release.h error.h mprintf.h updates.h strlist.h signature.h distribution.h debfile.h checkindeb.h checkindsc.h upgradelist.h target.h aptmethod.h downloadcache.h override.h terms.h ignore.h filterlist.h dpkgversions.h checkin.h exports.h globals.h tracking.h trackingt.h optionsfile.h readrelease.h donefile.h pull.h ar.h filelist.h contents.h chunkedit.h uploaderslist.h
MAINTAINERCLEANFILES = $(srcdir)/Makefile.in $(srcdir)/configure $(srcdir)/install-sh $(srcdir)/stamp-h.in $(srcdir)/aclocal.m4 $(srcdir)/config.h.in $(srcdir)/mkinstalldirs $(srcdir)/config.guess $(srcdir)/config.sub $(srcdir)/missing
......
Updates between 3.4.2 and ?:
Updates between 3.4.2 and 3.5.0:
- allow suite names as command line arguments
(when there is not codename of this name and only one distribution
has this suite name)
- generate and check Sha256, too.
Updates between 3.4.1 and 3.4.2:
now really fix the nasty bug with notifiers 3.4.1 should
......
......@@ -713,7 +713,7 @@ static inline retvalue gotcapabilities(struct aptmethod *method,const char *chun
static inline retvalue goturidone(struct aptmethod *method,const char *chunk,struct database *database) {
static const char * const method_hash_names[cs_COUNT] =
{ "MD5-Hash", "SHA1-Hash", // "SHA256-Hash"
{ "MD5-Hash", "SHA1-Hash", "SHA256-Hash",
"Size" };
retvalue result, r;
char *uri, *filename;
......
......@@ -38,9 +38,8 @@
extern int verbose;
static const char * const deb_checksum_headers[cs_COUNT] = {"MD5sum", "SHA1",
// "SHA256",
"Size"};
static const char * const deb_checksum_headers[cs_COUNT] = {
"MD5sum", "SHA1", "SHA256", "Size"};
/* get checksums out of a "Packages"-chunk. */
static retvalue binaries_parse_checksums(const char *chunk, /*@out@*/struct checksums **checksums_p) {
......
......@@ -36,10 +36,10 @@
#include "dirs.h"
const char * const changes_checksum_names[] = {
"Files", "Checksums-Sha1" //, "Checksums-Sha256"
"Files", "Checksums-Sha1", "Checksums-Sha256"
};
const char * const source_checksum_names[] = {
"Files", "Checksums-Sha1" //, "Checksums-Sha256"
"Files", "Checksums-Sha1", "Checksums-Sha256"
};
......@@ -70,7 +70,7 @@ struct checksums {
static const char * const hash_name[cs_COUNT] =
{ "md5", "sha1", "size" };
{ "md5", "sha1", "sha256", "size" };
void checksums_free(struct checksums *checksums) {
free(checksums);
......@@ -287,6 +287,12 @@ retvalue checksums_parse(struct checksums **checksums_p, const char *combinedche
while( *p != ' ' && *p != '\0' )
*(d++) = *(p++);
n->parts[cs_sha1sum].len = (hashlen_t)(d - start);
} else if( type == '2' ) {
start = d;
n->parts[cs_sha256sum].ofs = d - n->representation;
while( *p != ' ' && *p != '\0' )
*(d++) = *(p++);
n->parts[cs_sha256sum].len = (hashlen_t)(d - start);
} else {
while( *p != ' ' && *p != '\0' )
*(d++) = *(p++);
......@@ -506,6 +512,12 @@ retvalue checksums_combine(struct checksums **checksums_p, const struct checksum
while( *o != ' ' && *o != '\0' )
*(d++) = *(o++);
n->parts[cs_sha1sum].len = (hashlen_t)(d - start);
} else if( typeid == '2' ) {
start = d;
n->parts[cs_sha256sum].ofs = d - n->representation;
while( *o != ' ' && *o != '\0' )
*(d++) = *(o++);
n->parts[cs_sha256sum].len = (hashlen_t)(d - start);
} else
while( *o != ' ' && *o != '\0' )
*(d++) = *(o++);
......@@ -533,6 +545,14 @@ retvalue checksums_combine(struct checksums **checksums_p, const struct checksum
while( *b != ' ' && *b != '\0' )
*(d++) = *(b++);
n->parts[cs_sha1sum].len = (hashlen_t)(d - start);
} else if( typeid == '2' ) {
if( improvedhashes != NULL)
improvedhashes[cs_sha256sum] = true;
start = d;
n->parts[cs_sha256sum].ofs = d - n->representation;
while( *b != ' ' && *b != '\0' )
*(d++) = *(b++);
n->parts[cs_sha256sum].len = (hashlen_t)(d - start);
} else
while( *b != ' ' && *b != '\0' )
*(d++) = *(b++);
......@@ -811,7 +831,7 @@ retvalue checksumsarray_genfilelist(const struct checksumsarray *a, char **md5_p
}
*md5_p = filelines[cs_md5sum];
*sha1_p = filelines[cs_sha1sum];
*sha256_p = NULL;
*sha256_p = filelines[cs_sha256sum];
return RET_OK;
}
......@@ -1034,24 +1054,29 @@ retvalue checksums_hardlink(const char *directory, const char *filekey, const ch
void checksumscontext_init(struct checksumscontext *context) {
MD5Init(&context->md5);
SHA1Init(&context->sha1);
SHA256Init(&context->sha256);
}
void checksumscontext_update(struct checksumscontext *context, const unsigned char *data, size_t len) {
MD5Update(&context->md5, data, len);
// TODO: sha1 and sha256 share quite some stuff,
// the code can most likely be combined with quite some synergies..
SHA1Update(&context->sha1, data, len);
SHA256Update(&context->sha256, data, len);
}
static const char tab[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
retvalue checksums_from_context(struct checksums **out, struct checksumscontext *context) {
#define MD5_DIGEST_SIZE 16
unsigned char md5buffer[MD5_DIGEST_SIZE], sha1buffer[SHA1_DIGEST_SIZE];
unsigned char md5buffer[MD5_DIGEST_SIZE], sha1buffer[SHA1_DIGEST_SIZE],
sha256buffer[SHA256_DIGEST_SIZE];
char *d;
unsigned int i;
struct checksums *n;
n = malloc(sizeof(struct checksums) + 2*MD5_DIGEST_SIZE
+ 2*SHA1_DIGEST_SIZE + 26);
+ 2*SHA1_DIGEST_SIZE + 2*SHA256_DIGEST_SIZE + 30);
if( n == NULL )
return RET_ERROR_OOM;
memset(n, 0, sizeof(struct checksums));
......@@ -1068,7 +1093,19 @@ retvalue checksums_from_context(struct checksums **out, struct checksumscontext
}
*(d++) = ' ';
n->parts[cs_md5sum].ofs = 2*SHA1_DIGEST_SIZE+4;
*(d++) = ':';
*(d++) = '2';
*(d++) = ':';
n->parts[cs_sha256sum].ofs = d - n->representation;
n->parts[cs_sha256sum].len = 2*SHA256_DIGEST_SIZE;
SHA256Final(&context->sha256, sha256buffer);
for( i = 0 ; i < SHA256_DIGEST_SIZE ; i++ ) {
*(d++) = tab[sha256buffer[i] >> 4];
*(d++) = tab[sha256buffer[i] & 0xF];
}
*(d++) = ' ';
n->parts[cs_md5sum].ofs = d - n->representation;
assert( d - n->representation == n->parts[cs_md5sum].ofs);
n->parts[cs_md5sum].len = 2*MD5_DIGEST_SIZE;
MD5Final(md5buffer, &context->md5);
......@@ -1077,10 +1114,11 @@ retvalue checksums_from_context(struct checksums **out, struct checksumscontext
*(d++) = tab[md5buffer[i] & 0xF];
}
*(d++) = ' ';
n->parts[cs_length].ofs = 2*MD5_DIGEST_SIZE + 2*SHA1_DIGEST_SIZE + 5;
n->parts[cs_length].ofs = d - n->representation;
assert( d - n->representation == n->parts[cs_length].ofs);
n->parts[cs_length].len = (hashlen_t)snprintf(d,
2*MD5_DIGEST_SIZE + 2*SHA1_DIGEST_SIZE + 26
2*MD5_DIGEST_SIZE + 2*SHA1_DIGEST_SIZE
+ 2*SHA256_DIGEST_SIZE + 30
- (d - n->representation), "%lld",
(long long)context->sha1.count);
assert( strlen(d) == n->parts[cs_length].len );
......@@ -1090,7 +1128,8 @@ retvalue checksums_from_context(struct checksums **out, struct checksumscontext
bool checksums_iscomplete(const struct checksums *checksums) {
return checksums->parts[cs_md5sum].len != 0 &&
checksums->parts[cs_sha1sum].len != 0;
checksums->parts[cs_sha1sum].len != 0 &&
checksums->parts[cs_sha256sum].len != 0;
}
/* Collect missing checksums.
......
......@@ -15,6 +15,7 @@ enum checksumtype {
/* additionall hashes: */
#define cs_firstEXTENDED cs_sha1sum
cs_sha1sum,
cs_sha256sum,
#define cs_hashCOUNT cs_length
/* must be last but one */
cs_length,
......@@ -113,10 +114,14 @@ retvalue hashline_parse(const char *filenametoshow, const char *line, enum check
#ifndef REPREPRO_SHA1_H
#include "sha1.h"
#endif
#ifndef REPREPRO_SHA256_H
#include "sha256.h"
#endif
struct checksumscontext {
struct MD5Context md5;
struct SHA1_Context sha1;
struct SHA256_Context sha256;
};
void checksumscontext_init(/*@out@*/struct checksumscontext *);
......
reprepro (3.4.3-0) UNRELEASED; urgency=low
reprepro (3.5.0-0) UNRELEASED; urgency=low
* put --delete in reprepro.1's description of createsymlinks at the correct
place. (Closes: 481404)
* allow suite names in command line arguments (Closes: 481402)
* add support for Sha256
-- Bernhard R. Link <brlink@debian.org> Fri, 16 May 2008 18:34:07 +0200
-- Bernhard R. Link <brlink@debian.org> Sat, 17 May 2008 13:02:06 +0200
reprepro (3.4.2-1) unstable; urgency=high
......
......@@ -44,6 +44,9 @@ modified by James H. Brown <jbrown@burgoyne.com>, Saul Kravitz
<Saul.Kravitz@celera.com> and Ralph Giles <giles@ghostscript.com>
and in the public domain.
sha256.c is based on a file called sha256crypt.c, which is
Released into the Public Domain by Ulrich Drepper <drepper@redhat.com>.
docs/tiffany.example if derived from
http://ftp-master.debian.org/~ajt/tiffani/tiffani:
Copyright (C) 2004-5 Anthony Towns <aj@azure.humbug.org.au>
......
......@@ -32,7 +32,7 @@ retvalue release_getchecksums(const char *releasefile, struct checksumsarray *ou
char *chunk;
struct strlist files[cs_hashCOUNT];
static const char *release_checksum_names[cs_hashCOUNT] = {
"MD5Sum", "SHA1" // , "SHA256"
"MD5Sum", "SHA1", "SHA256"
};
enum checksumtype cs;
......
......@@ -1111,7 +1111,7 @@ retvalue release_prepare(struct release *release, struct distribution *distribut
enum checksumtype cs;
int i;
static const char * const release_checksum_headers[cs_hashCOUNT] =
{ "MD5Sum:\n", "SHA1:\n" };
{ "MD5Sum:\n", "SHA1:\n", "SHA256:\n" };
// TODO: check for existance of Release file here first?
if( onlyifneeded && !release->new ) {
......
/* sha256 implementation, taken (with minor modification) from sha256crypt.c,
which states:
Released into the Public Domain by Ulrich Drepper <drepper@redhat.com>.
Neglegible modifications by Bernhard R. Link, also in the public domain.
*/
#include <config.h>
#include <endian.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <sys/types.h>
#include "sha256.h"
#if __BYTE_ORDER == __LITTLE_ENDIAN
# define SWAP(n) \
(((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
#else
# define SWAP(n) (n)
#endif
/* This array contains the bytes used to pad the buffer to the next
64-byte boundary. (FIPS 180-2:5.1.1) */
static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
/* Constants for SHA256 from FIPS 180-2:4.2.2. */
static const uint32_t K[64] =
{
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
};
/* Process LEN bytes of BUFFER, accumulating context into CTX.
It is assumed that LEN % 64 == 0. */
static void
sha256_process_block (const void *buffer, size_t len, struct SHA256_Context *ctx)
{
const uint32_t *words = buffer;
size_t nwords = len / sizeof (uint32_t);
uint32_t a = ctx->H[0];
uint32_t b = ctx->H[1];
uint32_t c = ctx->H[2];
uint32_t d = ctx->H[3];
uint32_t e = ctx->H[4];
uint32_t f = ctx->H[5];
uint32_t g = ctx->H[6];
uint32_t h = ctx->H[7];
/* First increment the byte count. FIPS 180-2 specifies the possible
length of the file up to 2^64 bits. Here we only compute the
number of bytes. */
ctx->total += len;
/* Process all bytes in the buffer with 64 bytes in each round of
the loop. */
while (nwords > 0)
{
uint32_t W[64];
uint32_t a_save = a;
uint32_t b_save = b;
uint32_t c_save = c;
uint32_t d_save = d;
uint32_t e_save = e;
uint32_t f_save = f;
uint32_t g_save = g;
uint32_t h_save = h;
/* Operators defined in FIPS 180-2:4.1.2. */
#define Ch(x, y, z) ((x & y) ^ (~x & z))
#define Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z))
#define S0(x) (CYCLIC (x, 2) ^ CYCLIC (x, 13) ^ CYCLIC (x, 22))
#define S1(x) (CYCLIC (x, 6) ^ CYCLIC (x, 11) ^ CYCLIC (x, 25))
#define R0(x) (CYCLIC (x, 7) ^ CYCLIC (x, 18) ^ (x >> 3))
#define R1(x) (CYCLIC (x, 17) ^ CYCLIC (x, 19) ^ (x >> 10))
/* It is unfortunate that C does not provide an operator for
cyclic rotation. Hope the C compiler is smart enough. */
#define CYCLIC(w, s) ((w >> s) | (w << (32 - s)))
/* Compute the message schedule according to FIPS 180-2:6.2.2 step 2. */
for (unsigned int t = 0; t < 16; ++t)
{
W[t] = SWAP (*words);
++words;
}
for (unsigned int t = 16; t < 64; ++t)
W[t] = R1 (W[t - 2]) + W[t - 7] + R0 (W[t - 15]) + W[t - 16];
/* The actual computation according to FIPS 180-2:6.2.2 step 3. */
for (unsigned int t = 0; t < 64; ++t)
{
uint32_t T1 = h + S1 (e) + Ch (e, f, g) + K[t] + W[t];
uint32_t T2 = S0 (a) + Maj (a, b, c);
h = g;
g = f;
f = e;
e = d + T1;
d = c;
c = b;
b = a;
a = T1 + T2;
}
/* Add the starting values of the context according to FIPS 180-2:6.2.2
step 4. */
a += a_save;
b += b_save;
c += c_save;
d += d_save;
e += e_save;
f += f_save;
g += g_save;
h += h_save;
/* Prepare for the next round. */
nwords -= 16;
}
/* Put checksum in context given as argument. */
ctx->H[0] = a;
ctx->H[1] = b;
ctx->H[2] = c;
ctx->H[3] = d;
ctx->H[4] = e;
ctx->H[5] = f;
ctx->H[6] = g;
ctx->H[7] = h;
}
/* Initialize structure containing state of computation.
(FIPS 180-2:5.3.2) */
void
SHA256Init(struct SHA256_Context *ctx)
{
ctx->H[0] = 0x6a09e667;
ctx->H[1] = 0xbb67ae85;
ctx->H[2] = 0x3c6ef372;
ctx->H[3] = 0xa54ff53a;
ctx->H[4] = 0x510e527f;
ctx->H[5] = 0x9b05688c;
ctx->H[6] = 0x1f83d9ab;
ctx->H[7] = 0x5be0cd19;
ctx->total = 0;
ctx->buflen = 0;
}
/* Process the remaining bytes in the internal buffer and the usual
prolog according to the standard and write the result to digest.
*/
void
SHA256Final(struct SHA256_Context *ctx, uint8_t *digest)
{
/* Take yet unprocessed bytes into account. */
uint32_t bytes = ctx->buflen;
size_t pad;
int i;
/* Now count remaining bytes. */
ctx->total += bytes;
pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
memcpy (&ctx->buffer[bytes], fillbuf, pad);
/* Put the 64-bit file length in *bits* at the end of the buffer. */
*(uint32_t *) &ctx->buffer[bytes + pad + 4] = SWAP (ctx->total << 3);
*(uint32_t *) &ctx->buffer[bytes + pad] = SWAP (ctx->total >> 29);
/* Process last bytes. */
sha256_process_block (ctx->buffer, bytes + pad + 8, ctx);
for (i = 0; i < SHA256_DIGEST_SIZE; i++) {
digest[i] = (uint8_t)
((ctx->H[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
}
}
void
SHA256Update(struct SHA256_Context *ctx, const uint8_t *buffer, size_t len)
{
/* When we already have some bits in our internal buffer concatenate
both inputs first. */
if (ctx->buflen != 0)
{
size_t left_over = ctx->buflen;
size_t add = 128 - left_over > len ? len : 128 - left_over;
memcpy (&ctx->buffer[left_over], buffer, add);
ctx->buflen += add;
if (ctx->buflen > 64)
{
sha256_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
ctx->buflen &= 63;
/* The regions in the following copy operation cannot overlap. */
memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
ctx->buflen);
}
buffer = buffer + add;
len -= add;
}
/* Process available complete blocks. */
if (len >= 64)
{
/* To check alignment gcc has an appropriate operator. Other
compilers don't. */
#if __GNUC__ >= 2
# define UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint32_t) != 0)
#else
# define UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint32_t) != 0)
#endif
if (UNALIGNED_P (buffer))
while (len > 64)
{
sha256_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
buffer = buffer + 64;
len -= 64;
}
else
{
sha256_process_block (buffer, len & ~63, ctx);
buffer = buffer + (len & ~63);
len &= 63;
}
}
/* Move remaining bytes into internal buffer. */
if (len > 0)
{
size_t left_over = ctx->buflen;
memcpy (&ctx->buffer[left_over], buffer, len);
left_over += len;
if (left_over >= 64)
{
sha256_process_block (ctx->buffer, 64, ctx);
left_over -= 64;
memcpy (ctx->buffer, &ctx->buffer[64], left_over);
}
ctx->buflen = left_over;
}
}
#ifndef REPREPRO_SHA256_H
#define REPREPRO_SHA256_H
/* Structure to save state of computation between the single steps. */
struct SHA256_Context
{
uint32_t H[8];
uint64_t total;
uint32_t buflen;
char buffer[128]; /* NB: always correctly aligned for uint32_t. */
};
#define SHA256_DIGEST_SIZE 32
void SHA256Init(/*@out@*/struct SHA256_Context *context);
void SHA256Update(struct SHA256_Context *context, const uint8_t *data, size_t len);
void SHA256Final(struct SHA256_Context *context, /*@out@*/uint8_t digest[SHA256_DIGEST_SIZE]);
#endif
......@@ -245,6 +245,7 @@ H
'd i
Filename: $FILENAME
Size: $(stat -c "%s" "$FILENAME")
SHA256: $(sha256sum "$FILENAME" | cut -d' ' -f1)
SHA1: $(sha1sum "$FILENAME" | cut -d' ' -f1)
MD5sum: $(md5sum "$FILENAME" | cut -d' ' -f1)
.
......@@ -274,9 +275,18 @@ cat <<EOF
$(sha1sum "$1" | cut -d' ' -f1) $(stat -c "%s" "$1")
EOF
}
function sha2() {
echo -n ":2:"
sha256sum "$1" | cut -d' ' -f1
}
function sha2andsize() {
cat <<EOF
$(sha256sum "$1" | cut -d' ' -f1) $(stat -c "%s" "$1")
EOF
}
function fullchecksum() {
cat <<EOF
$(sha "$1") $(md5sum "$1" | cut -d' ' -f1) $(stat -c "%s" "$1")
$(sha "$1") $(sha2 "$1") $(md5sum "$1" | cut -d' ' -f1) $(stat -c "%s" "$1")
EOF
}
EMPTYMD5ONLY="d41d8cd98f00b204e9800998ecf8427e"
......@@ -286,5 +296,8 @@ EMPTYBZ2MD5="4059d198768f9f8dc9372dc1c54bc3c3 14"
EMPTYSHA1="da39a3ee5e6b4b0d3255bfef95601890afd80709 0"
EMPTYGZSHA1="46c6643f07aa7f6bfe7118de926b86defc5087c4 20"
EMPTYBZ2SHA1="64a543afbb5f4bf728636bdcbbe7a2ed0804adc2 14"
EMPTYSHA2="e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 0"
EMPTYGZSHA2="59869db34853933b239f1e2219cf7d431da006aa919635478511fabbfc8849d2 20"
EMPTYBZ2SHA2="d3dda84eb03b9738d118eb2be78e246106900493c0ae07819ad60815134a8058 14"
setoptions default "" ""
......@@ -339,6 +339,8 @@ DSCMD5S="$(mdandsize i/bird_1.dsc)"
TARMD5S="$(mdandsize i/bird_1.tar.gz)"
DSCSHA1S="$(sha1andsize i/bird_1.dsc)"
TARSHA1S="$(sha1andsize i/bird_1.tar.gz)"
DSCSHA2S="$(sha2andsize i/bird_1.dsc)"
TARSHA2S="$(sha2andsize i/bird_1.tar.gz)"
testrun - -b . processincoming default 3<<EOF
returns 255
stderr
......@@ -451,6 +453,9 @@ $ a
Checksums-Sha1:
$DSCSHA1S bird_1.dsc
$TARSHA1S bird_1.tar.gz
Checksums-Sha256:
$DSCSHA2S bird_1.dsc
$TARSHA2S bird_1.tar.gz
.
w
......@@ -571,6 +576,9 @@ $ a
Checksums-Sha1:
$DSCSHA1S bird_1.dsc
$TARSHA1S bird_1.tar.gz
Checksums-Sha256:
$DSCSHA2S bird_1.dsc
$TARSHA2S bird_1.tar.gz
.
w
......@@ -580,6 +588,8 @@ BIRDDSCMD5S="$DSCMD5S"
BIRDTARMD5S="$TARMD5S"
BIRDDSCSHA1S="$DSCSHA1S"
BIRDTARSHA1S="$TARSHA1S"
BIRDDSCSHA2S="$DSCSHA2S"
BIRDTARSHA2S="$TARSHA2S"
gunzip -c dists/B/cat/source/Sources.gz > results
dodiff results.expected results
......@@ -1160,6 +1170,7 @@ printf "1i\nFormat: 1.0\n.\nw\nq\n" | ed -s i/dscfilename_fileversion~.dsc
DSCMD5S="$(mdandsize i/dscfilename_fileversion~.dsc )"
OLDDSCFILENAMEMD5S="$DSCMD5S"
OLDDSCFILENAMESHA1S="$(sha1andsize i/dscfilename_fileversion~.dsc)"
OLDDSCFILENAMESHA2S="$(sha2andsize i/dscfilename_fileversion~.dsc)"
printf '$d\nw\nq\n' | ed -s i/test.changes
echo " $DSCMD5S dummy can't-live-without dscfilename_fileversion~.dsc" >> i/test.changes
checknolog logfile
......@@ -1284,8 +1295,10 @@ printf '$d\nw\nq\n' | ed -s i/dscfilename_fileversion~.dsc
echo " 31a1096ff883d52f0c1f39e652d6336f 33 strangefile_xyz" >> i/dscfilename_fileversion~.dsc
DSCMD5S="$(mdandsize i/dscfilename_fileversion~.dsc)"
DSCSHA1S="$(sha1andsize i/dscfilename_fileversion~.dsc)"
DSCSHA2S="$(sha2andsize i/dscfilename_fileversion~.dsc)"
DSCFILENAMEMD5S="$DSCMD5S"
DSCFILENAMESHA1S="$DSCSHA1S"
DSCFILENAMESHA2S="$DSCSHA2S"
printf '$-1,$d\nw\nq\n' | ed -s i/test.changes
echo " $DSCMD5S dummy unneeded dscfilename_fileversion~.dsc" >> i/test.changes
echo " 33a1096ff883d52f0c1f39e652d6336f 33 - - strangefile_xyz" >> i/test.changes
......@@ -1359,6 +1372,9 @@ $ a
Checksums-Sha1:
$BIRDDSCSHA1S bird_1.dsc
$BIRDTARSHA1S bird_1.tar.gz
Checksums-Sha256:
$BIRDDSCSHA2S bird_1.dsc
$BIRDTARSHA2S bird_1.tar.gz
.
w
......@@ -1377,6 +1393,8 @@ Files:
$OLDDSCFILENAMEMD5S dscfilename_versionindsc.dsc
Checksums-Sha1:
$OLDDSCFILENAMESHA1S dscfilename_versionindsc.dsc
Checksums-Sha256:
$OLDDSCFILENAMESHA2S dscfilename_versionindsc.dsc
EOF
dodiff results.expected results
......@@ -1545,6 +1563,9 @@ Files:
Checksums-Sha1:
$DSCFILENAMESHA1S dscfilename_newversion~.dsc
4453da6ca46859b207c5b55af6213ff8369cd383 33 strangefile_xyz
Checksums-Sha256:
$DSCFILENAMESHA2S dscfilename_newversion~.dsc
c40fcf711220c0ce210159d43b22f1f59274819bf3575e11cc0057ed1988a575 33 strangefile_xyz
EOF
dodiff results.expected results
......@@ -1692,7 +1713,7 @@ SHA1:
$EMPTYGZSHA1 stupid/source/Sources.gz
$EMPTYBZ2SHA1 stupid/source/Sources.bz2
ff71705a4cadaec55de5a6ebbfcd726caf2e2606 39 stupid/source/Release
da39a3ee5e6b4b0d3255bfef95601890afd80709 0 ugly/binary-${FAKEARCHITECTURE}/Packages
$EMPTYSHA1 ugly/binary-${FAKEARCHITECTURE}/Packages
$EMPTYGZSHA1 ugly/binary-${FAKEARCHITECTURE}/Packages.gz
$EMPTYBZ2SHA1 ugly/binary-${FAKEARCHITECTURE}/Packages.bz2
$(sha1andsize dists/test1/ugly/binary-${FAKEARCHITECTURE}/Release) ugly/binary-${FAKEARCHITECTURE}/Release
......@@ -1700,6 +1721,23 @@ SHA1:
$EMPTYGZSHA1 ugly/source/Sources.gz
$EMPTYBZ2SHA1 ugly/source/Sources.bz2
b297876e9d6ee3ee6083160003755047ede22a96 37 ugly/source/Release
SHA256:
$(sha2andsize dists/test1/stupid/binary-${FAKEARCHITECTURE}/Packages) stupid/binary-${FAKEARCHITECTURE}/Packages
$EMPTYGZSHA2 stupid/binary-${FAKEARCHITECTURE}/Packages.gz
$EMPTYBZ2SHA2 stupid/binary-${FAKEARCHITECTURE}/Packages.bz2
$(sha2andsize dists/test1/stupid/binary-${FAKEARCHITECTURE}/Release) stupid/binary-${FAKEARCHITECTURE}/Release
$EMPTYSHA2 stupid/source/Sources
$EMPTYGZSHA2 stupid/source/Sources.gz
$EMPTYBZ2SHA2 stupid/source/Sources.bz2
b88352d8e0227a133e2236c3a8961581562ee285980fc20bb79626d0d208aa51 39 stupid/source/Release
$EMPTYSHA2 ugly/binary-${FAKEARCHITECTURE}/Packages
$EMPTYGZSHA2 ugly/binary-${FAKEARCHITECTURE}/Packages.gz
$EMPTYBZ2SHA2 ugly/binary-${FAKEARCHITECTURE}/Packages.bz2
$(sha2andsize dists/test1/ugly/binary-${FAKEARCHITECTURE}/Release) ugly/binary-${FAKEARCHITECTURE}/Release
$EMPTYSHA2 ugly/source/Sources
$EMPTYGZSHA2 ugly/source/Sources.gz
$EMPTYBZ2SHA2 ugly/source/Sources.bz2
edb5450a3f98a140b938c8266b8b998ba8f426c80ac733fe46423665d5770d9f 37 ugly/source/Release
END
cat > dists/test2/stupid/binary-${FAKEARCHITECTURE}/Release.expected <<END
Archive: broken
......@@ -1781,6 +1819,31 @@ SHA1:
$EMPTYGZSHA1 ugly/source/Sources.gz
$EMPTYBZ2SHA1 ugly/source/Sources.bz2
$(sha1andsize dists/test2/ugly/source/Release) ugly/source/Release
SHA256:
$EMPTYSHA2 stupid/binary-${FAKEARCHITECTURE}/Packages
$EMPTYGZSHA2 stupid/binary-${FAKEARCHITECTURE}/Packages.gz
$EMPTYBZ2SHA2 stupid/binary-${FAKEARCHITECTURE}/Packages.bz2
$(sha2andsize dists/test2/stupid/binary-${FAKEARCHITECTURE}/Release) stupid/binary-${FAKEARCHITECTURE}/Release
$EMPTYSHA2 stupid/binary-coal/Packages
$EMPTYGZSHA2 stupid/binary-coal/Packages.gz
$EMPTYBZ2SHA2 stupid/binary-coal/Packages.bz2
$(sha2andsize dists/test2/stupid/binary-coal/Release) stupid/binary-coal/Release
$EMPTYSHA2 stupid/source/Sources
$EMPTYGZSHA2 stupid/source/Sources.gz
$EMPTYBZ2SHA2 stupid/source/Sources.bz2
$(sha2andsize dists/test2/stupid/source/Release) stupid/source/Release
$EMPTYSHA2 ugly/binary-${FAKEARCHITECTURE}/Packages
$EMPTYGZSHA2 ugly/binary-${FAKEARCHITECTURE}/Packages.gz
$EMPTYBZ2SHA2 ugly/binary-${FAKEARCHITECTURE}/Packages.bz2
$(sha2andsize dists/test2/ugly/binary-${FAKEARCHITECTURE}/Release) ugly/binary-${FAKEARCHITECTURE}/Release
$EMPTYSHA2 ugly/binary-coal/Packages
$EMPTYGZSHA2 ugly/binary-coal/Packages.gz
$EMPTYBZ2SHA2 ugly/binary-coal/Packages.bz2
$(sha2andsize dists/test2/ugly/binary-coal/Release) ugly/binary-coal/Release
$EMPTYSHA2 ugly/source/Sources
$EMPTYGZSHA2 ugly/source/Sources.gz
$EMPTYBZ2SHA2 ugly/source/Sources.bz2
$(sha2andsize dists/test2/ugly/source/Release) ugly/source/Release
END
printf '%%g/^Date:/s/Date: .*/Date: normalized/\n%%g/gz$/s/^ 163be0a88c70ca629fd516dbaadad96a / 7029066c27ac6f5ef18d660d5741979a /\nw\nq\n' | ed -s dists/test1/Release
printf '%%g/^Date:/s/Date: .*/Date: normalized/\n%%g/gz$/s/^ 163be0a88c70ca629fd516dbaadad96a / 7029066c27ac6f5ef18d660d5741979a /\nw\nq\n' | ed -s dists/test2/Release
......
......@@ -513,7 +513,7 @@ static retvalue parse_changes_files(struct changes *c, struct strlist filelines[
return RET_ERROR_OOM;