|
|
6d394f |
diff -Naur bacula-9.0.0.old/src/lib/lib.h bacula-9.0.0/src/lib/lib.h
|
|
|
6d394f |
--- bacula-9.0.0.old/src/lib/lib.h 2017-07-10 08:52:38.928834471 +0200
|
|
|
6d394f |
+++ bacula-9.0.0/src/lib/lib.h 2017-07-10 09:06:14.956314468 +0200
|
|
|
6d394f |
@@ -53,7 +53,6 @@
|
|
|
6d394f |
#include "fnmatch.h"
|
|
|
6d394f |
#endif
|
|
|
6d394f |
#include "md5.h"
|
|
|
6d394f |
-#include "sha1.h"
|
|
|
6d394f |
#include "tree.h"
|
|
|
6d394f |
#include "watchdog.h"
|
|
|
6d394f |
#include "btimers.h"
|
|
|
6d394f |
diff -Naur bacula-9.0.0.old/src/lib/Makefile.in bacula-9.0.0/src/lib/Makefile.in
|
|
|
6d394f |
--- bacula-9.0.0.old/src/lib/Makefile.in 2017-07-10 08:52:38.928834471 +0200
|
|
|
6d394f |
+++ bacula-9.0.0/src/lib/Makefile.in 2017-07-10 09:06:49.445973039 +0200
|
|
|
6d394f |
@@ -38,7 +38,7 @@
|
|
|
6d394f |
flist.h fnmatch.h guid_to_name.h htable.h lex.h \
|
|
|
6d394f |
lib.h lz4.h md5.h mem_pool.h message.h \
|
|
|
6d394f |
openssl.h parse_conf.h plugins.h protos.h queue.h rblist.h \
|
|
|
6d394f |
- runscript.h rwlock.h serial.h sellist.h sha1.h sha2.h \
|
|
|
6d394f |
+ runscript.h rwlock.h serial.h sellist.h sha2.h \
|
|
|
6d394f |
smartall.h status.h tls.h tree.h var.h \
|
|
|
6d394f |
watchdog.h workq.h ini.h \
|
|
|
6d394f |
lockmgr.h devlock.h output.h bwlimit.h
|
|
|
6d394f |
@@ -52,7 +52,7 @@
|
|
|
6d394f |
guid_to_name.c hmac.c jcr.c lex.c lz4.c alist.c dlist.c \
|
|
|
6d394f |
md5.c message.c mem_pool.c openssl.c \
|
|
|
6d394f |
plugins.c priv.c queue.c bregex.c \
|
|
|
6d394f |
- runscript.c rwlock.c scan.c sellist.c serial.c sha1.c sha2.c \
|
|
|
6d394f |
+ runscript.c rwlock.c scan.c sellist.c serial.c sha2.c \
|
|
|
6d394f |
signal.c smartall.c rblist.c tls.c tree.c \
|
|
|
6d394f |
util.c var.c watchdog.c workq.c btimers.c \
|
|
|
6d394f |
worker.c flist.c \
|
|
|
6d394f |
@@ -218,13 +218,6 @@
|
|
|
6d394f |
$(RMF) md5.o
|
|
|
6d394f |
$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) md5.c
|
|
|
6d394f |
|
|
|
6d394f |
-sha1sum: Makefile sha1.o
|
|
|
6d394f |
- $(RMF) sha1.o
|
|
|
6d394f |
- $(CXX) -DSHA1_SUM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) sha1.c
|
|
|
6d394f |
- $(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ sha1.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
|
|
|
6d394f |
- $(RMF) sha1.o
|
|
|
6d394f |
- $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) sha1.c
|
|
|
6d394f |
-
|
|
|
6d394f |
bsnprintf: Makefile bsnprintf.o
|
|
|
6d394f |
$(RMF) bsnprintf.o
|
|
|
6d394f |
$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) bsnprintf.c
|
|
|
6d394f |
@@ -274,7 +267,7 @@
|
|
|
6d394f |
|
|
|
6d394f |
clean: libtool-clean
|
|
|
6d394f |
@$(RMF) core a.out *.o *.bak *.tex *.pdf *~ *.intpro *.extpro 1 2 3
|
|
|
6d394f |
- @$(RMF) rwlock_test md5sum sha1sum
|
|
|
6d394f |
+ @$(RMF) rwlock_test md5sum
|
|
|
6d394f |
|
|
|
6d394f |
realclean: clean
|
|
|
6d394f |
@$(RMF) tags
|
|
|
6d394f |
diff -Naur bacula-9.0.0.old/src/lib/sha1.c bacula-9.0.0/src/lib/sha1.c
|
|
|
6d394f |
--- bacula-9.0.0.old/src/lib/sha1.c 2017-07-10 08:52:38.929834490 +0200
|
|
|
6d394f |
+++ bacula-9.0.0/src/lib/sha1.c 1970-01-01 01:00:00.000000000 +0100
|
|
|
6d394f |
@@ -1,510 +0,0 @@
|
|
|
6d394f |
-/*
|
|
|
6d394f |
- * sha1.c
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Description:
|
|
|
6d394f |
- * This file implements the Secure Hashing Algorithm 1 as
|
|
|
6d394f |
- * defined in FIPS PUB 180-1 published April 17, 1995.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * The SHA-1, produces a 160-bit message digest for a given
|
|
|
6d394f |
- * data stream. It should take about 2**n steps to find a
|
|
|
6d394f |
- * message with the same digest as a given message and
|
|
|
6d394f |
- * 2**(n/2) to find any two messages with the same digest,
|
|
|
6d394f |
- * when n is the digest size in bits. Therefore, this
|
|
|
6d394f |
- * algorithm can serve as a means of providing a
|
|
|
6d394f |
- * "fingerprint" for a message.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Portability Issues:
|
|
|
6d394f |
- * SHA-1 is defined in terms of 32-bit "words". This code
|
|
|
6d394f |
- * uses <stdint.h> (included via "sha1.h" to define 32 and 8
|
|
|
6d394f |
- * bit unsigned integer types. If your C compiler does not
|
|
|
6d394f |
- * support 32 bit unsigned integers, this code is not
|
|
|
6d394f |
- * appropriate.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Caveats:
|
|
|
6d394f |
- * SHA-1 is designed to work with messages less than 2^64 bits
|
|
|
6d394f |
- * long. Although SHA-1 allows a message digest to be generated
|
|
|
6d394f |
- * for messages of any number of bits less than 2^64, this
|
|
|
6d394f |
- * implementation only works with messages with a length that is
|
|
|
6d394f |
- * a multiple of the size of an 8-bit character.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * See sha1.h for copyright
|
|
|
6d394f |
- */
|
|
|
6d394f |
-
|
|
|
6d394f |
-#include "sha1.h"
|
|
|
6d394f |
-
|
|
|
6d394f |
-/*
|
|
|
6d394f |
- * Define the SHA1 circular left shift macro
|
|
|
6d394f |
- */
|
|
|
6d394f |
-#define SHA1CircularShift(bits,word) \
|
|
|
6d394f |
- (((word) << (bits)) | ((word) >> (32-(bits))))
|
|
|
6d394f |
-
|
|
|
6d394f |
-/* Local Function Prototyptes */
|
|
|
6d394f |
-static void SHA1PadMessage(SHA1Context *);
|
|
|
6d394f |
-static void SHA1ProcessMessageBlock(SHA1Context *);
|
|
|
6d394f |
-
|
|
|
6d394f |
-/*
|
|
|
6d394f |
- * SHA1Init
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Description:
|
|
|
6d394f |
- * This function will initialize the SHA1Context in preparation
|
|
|
6d394f |
- * for computing a new SHA1 message digest.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Parameters:
|
|
|
6d394f |
- * context: [in/out]
|
|
|
6d394f |
- * The context to reset.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Returns:
|
|
|
6d394f |
- * sha Error Code.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- */
|
|
|
6d394f |
-int SHA1Init(SHA1Context *context)
|
|
|
6d394f |
-{
|
|
|
6d394f |
- if (!context)
|
|
|
6d394f |
- {
|
|
|
6d394f |
- return shaNull;
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- context->Length_Low = 0;
|
|
|
6d394f |
- context->Length_High = 0;
|
|
|
6d394f |
- context->Message_Block_Index = 0;
|
|
|
6d394f |
-
|
|
|
6d394f |
- context->Intermediate_Hash[0] = 0x67452301;
|
|
|
6d394f |
- context->Intermediate_Hash[1] = 0xEFCDAB89;
|
|
|
6d394f |
- context->Intermediate_Hash[2] = 0x98BADCFE;
|
|
|
6d394f |
- context->Intermediate_Hash[3] = 0x10325476;
|
|
|
6d394f |
- context->Intermediate_Hash[4] = 0xC3D2E1F0;
|
|
|
6d394f |
-
|
|
|
6d394f |
- context->Computed = 0;
|
|
|
6d394f |
- context->Corrupted = 0;
|
|
|
6d394f |
-
|
|
|
6d394f |
- return shaSuccess;
|
|
|
6d394f |
-}
|
|
|
6d394f |
-
|
|
|
6d394f |
-/*
|
|
|
6d394f |
- * SHA1Final
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Description:
|
|
|
6d394f |
- * This function will return the 160-bit message digest into the
|
|
|
6d394f |
- * Message_Digest array provided by the caller.
|
|
|
6d394f |
- * NOTE: The first octet of hash is stored in the 0th element,
|
|
|
6d394f |
- * the last octet of hash in the 19th element.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Parameters:
|
|
|
6d394f |
- * context: [in/out]
|
|
|
6d394f |
- * The context to use to calculate the SHA-1 hash.
|
|
|
6d394f |
- * Message_Digest: [out]
|
|
|
6d394f |
- * Where the digest is returned.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Returns:
|
|
|
6d394f |
- * sha Error Code.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- */
|
|
|
6d394f |
-int SHA1Final(SHA1Context *context,
|
|
|
6d394f |
- uint8_t Message_Digest[SHA1HashSize])
|
|
|
6d394f |
-{
|
|
|
6d394f |
- int i;
|
|
|
6d394f |
-
|
|
|
6d394f |
- if (!context || !Message_Digest) {
|
|
|
6d394f |
- return shaNull;
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- if (context->Corrupted) {
|
|
|
6d394f |
- return context->Corrupted;
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- if (!context->Computed) {
|
|
|
6d394f |
- SHA1PadMessage(context);
|
|
|
6d394f |
- for(i=0; i<64; ++i) {
|
|
|
6d394f |
- /* message may be sensitive, clear it out */
|
|
|
6d394f |
- context->Message_Block[i] = 0;
|
|
|
6d394f |
- }
|
|
|
6d394f |
- context->Length_Low = 0; /* and clear length */
|
|
|
6d394f |
- context->Length_High = 0;
|
|
|
6d394f |
- context->Computed = 1;
|
|
|
6d394f |
-
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- for(i = 0; i < SHA1HashSize; ++i) {
|
|
|
6d394f |
- Message_Digest[i] = context->Intermediate_Hash[i>>2]
|
|
|
6d394f |
- >> 8 * ( 3 - ( i & 0x03 ) );
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- return shaSuccess;
|
|
|
6d394f |
-}
|
|
|
6d394f |
-
|
|
|
6d394f |
-/*
|
|
|
6d394f |
- * SHA1Update
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Description:
|
|
|
6d394f |
- * This function accepts an array of octets as the next portion
|
|
|
6d394f |
- * of the message.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Parameters:
|
|
|
6d394f |
- * context: [in/out]
|
|
|
6d394f |
- * The SHA context to update
|
|
|
6d394f |
- * message_array: [in]
|
|
|
6d394f |
- * An array of characters representing the next portion of
|
|
|
6d394f |
- * the message.
|
|
|
6d394f |
- * length: [in]
|
|
|
6d394f |
- * The length of the message in message_array
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Returns:
|
|
|
6d394f |
- * sha Error Code.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- */
|
|
|
6d394f |
-int SHA1Update(SHA1Context *context,
|
|
|
6d394f |
- const uint8_t *message_array,
|
|
|
6d394f |
- unsigned length)
|
|
|
6d394f |
-{
|
|
|
6d394f |
- if (!length) {
|
|
|
6d394f |
- return shaSuccess;
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- if (!context || !message_array) {
|
|
|
6d394f |
- return shaNull;
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- if (context->Computed) {
|
|
|
6d394f |
- context->Corrupted = shaStateError;
|
|
|
6d394f |
-
|
|
|
6d394f |
- return shaStateError;
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- if (context->Corrupted) {
|
|
|
6d394f |
- return context->Corrupted;
|
|
|
6d394f |
- }
|
|
|
6d394f |
- while(length-- && !context->Corrupted) {
|
|
|
6d394f |
- context->Message_Block[context->Message_Block_Index++] =
|
|
|
6d394f |
- (*message_array & 0xFF);
|
|
|
6d394f |
-
|
|
|
6d394f |
- context->Length_Low += 8;
|
|
|
6d394f |
- if (context->Length_Low == 0) {
|
|
|
6d394f |
- context->Length_High++;
|
|
|
6d394f |
- if (context->Length_High == 0) {
|
|
|
6d394f |
- /* Message is too long */
|
|
|
6d394f |
- context->Corrupted = 1;
|
|
|
6d394f |
- }
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- if (context->Message_Block_Index == 64) {
|
|
|
6d394f |
- SHA1ProcessMessageBlock(context);
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- message_array++;
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- return shaSuccess;
|
|
|
6d394f |
-}
|
|
|
6d394f |
-
|
|
|
6d394f |
-/*
|
|
|
6d394f |
- * SHA1ProcessMessageBlock
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Description:
|
|
|
6d394f |
- * This function will process the next 512 bits of the message
|
|
|
6d394f |
- * stored in the Message_Block array.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Parameters:
|
|
|
6d394f |
- * None.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Returns:
|
|
|
6d394f |
- * Nothing.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Comments:
|
|
|
6d394f |
-
|
|
|
6d394f |
- * Many of the variable names in this code, especially the
|
|
|
6d394f |
- * single character names, were used because those were the
|
|
|
6d394f |
- * names used in the publication.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- *
|
|
|
6d394f |
- */
|
|
|
6d394f |
-static void SHA1ProcessMessageBlock(SHA1Context *context)
|
|
|
6d394f |
-{
|
|
|
6d394f |
- const uint32_t K[] = { /* Constants defined in SHA-1 */
|
|
|
6d394f |
- 0x5A827999,
|
|
|
6d394f |
- 0x6ED9EBA1,
|
|
|
6d394f |
- 0x8F1BBCDC,
|
|
|
6d394f |
- 0xCA62C1D6
|
|
|
6d394f |
- };
|
|
|
6d394f |
- int t; /* Loop counter */
|
|
|
6d394f |
- uint32_t temp; /* Temporary word value */
|
|
|
6d394f |
- uint32_t W[80]; /* Word sequence */
|
|
|
6d394f |
- uint32_t A, B, C, D, E; /* Word buffers */
|
|
|
6d394f |
-
|
|
|
6d394f |
- /*
|
|
|
6d394f |
- * Initialize the first 16 words in the array W
|
|
|
6d394f |
- */
|
|
|
6d394f |
- for(t = 0; t < 16; t++) {
|
|
|
6d394f |
- W[t] = context->Message_Block[t * 4] << 24;
|
|
|
6d394f |
- W[t] |= context->Message_Block[t * 4 + 1] << 16;
|
|
|
6d394f |
- W[t] |= context->Message_Block[t * 4 + 2] << 8;
|
|
|
6d394f |
- W[t] |= context->Message_Block[t * 4 + 3];
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- for(t = 16; t < 80; t++) {
|
|
|
6d394f |
- W[t] = SHA1CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]);
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- A = context->Intermediate_Hash[0];
|
|
|
6d394f |
- B = context->Intermediate_Hash[1];
|
|
|
6d394f |
- C = context->Intermediate_Hash[2];
|
|
|
6d394f |
- D = context->Intermediate_Hash[3];
|
|
|
6d394f |
- E = context->Intermediate_Hash[4];
|
|
|
6d394f |
-
|
|
|
6d394f |
- for(t = 0; t < 20; t++) {
|
|
|
6d394f |
- temp = SHA1CircularShift(5,A) +
|
|
|
6d394f |
- ((B & C) | ((~B) & D)) + E + W[t] + K[0];
|
|
|
6d394f |
- E = D;
|
|
|
6d394f |
- D = C;
|
|
|
6d394f |
- C = SHA1CircularShift(30,B);
|
|
|
6d394f |
-
|
|
|
6d394f |
- B = A;
|
|
|
6d394f |
- A = temp;
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- for(t = 20; t < 40; t++) {
|
|
|
6d394f |
- temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1];
|
|
|
6d394f |
- E = D;
|
|
|
6d394f |
- D = C;
|
|
|
6d394f |
- C = SHA1CircularShift(30,B);
|
|
|
6d394f |
- B = A;
|
|
|
6d394f |
- A = temp;
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- for(t = 40; t < 60; t++) {
|
|
|
6d394f |
- temp = SHA1CircularShift(5,A) +
|
|
|
6d394f |
- ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2];
|
|
|
6d394f |
- E = D;
|
|
|
6d394f |
- D = C;
|
|
|
6d394f |
- C = SHA1CircularShift(30,B);
|
|
|
6d394f |
- B = A;
|
|
|
6d394f |
- A = temp;
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- for(t = 60; t < 80; t++) {
|
|
|
6d394f |
- temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3];
|
|
|
6d394f |
- E = D;
|
|
|
6d394f |
- D = C;
|
|
|
6d394f |
- C = SHA1CircularShift(30,B);
|
|
|
6d394f |
- B = A;
|
|
|
6d394f |
- A = temp;
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- context->Intermediate_Hash[0] += A;
|
|
|
6d394f |
- context->Intermediate_Hash[1] += B;
|
|
|
6d394f |
- context->Intermediate_Hash[2] += C;
|
|
|
6d394f |
- context->Intermediate_Hash[3] += D;
|
|
|
6d394f |
- context->Intermediate_Hash[4] += E;
|
|
|
6d394f |
-
|
|
|
6d394f |
- context->Message_Block_Index = 0;
|
|
|
6d394f |
-}
|
|
|
6d394f |
-
|
|
|
6d394f |
-/*
|
|
|
6d394f |
- * SHA1PadMessage
|
|
|
6d394f |
- *
|
|
|
6d394f |
-
|
|
|
6d394f |
- * Description:
|
|
|
6d394f |
- * According to the standard, the message must be padded to an even
|
|
|
6d394f |
- * 512 bits. The first padding bit must be a '1'. The last 64
|
|
|
6d394f |
- * bits represent the length of the original message. All bits in
|
|
|
6d394f |
- * between should be 0. This function will pad the message
|
|
|
6d394f |
- * according to those rules by filling the Message_Block array
|
|
|
6d394f |
- * accordingly. It will also call the ProcessMessageBlock function
|
|
|
6d394f |
- * provided appropriately. When it returns, it can be assumed that
|
|
|
6d394f |
- * the message digest has been computed.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Parameters:
|
|
|
6d394f |
- * context: [in/out]
|
|
|
6d394f |
- * The context to pad
|
|
|
6d394f |
- * ProcessMessageBlock: [in]
|
|
|
6d394f |
- * The appropriate SHA*ProcessMessageBlock function
|
|
|
6d394f |
- * Returns:
|
|
|
6d394f |
- * Nothing.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- */
|
|
|
6d394f |
-
|
|
|
6d394f |
-static void SHA1PadMessage(SHA1Context *context)
|
|
|
6d394f |
-{
|
|
|
6d394f |
- /*
|
|
|
6d394f |
- * Check to see if the current message block is too small to hold
|
|
|
6d394f |
- * the initial padding bits and length. If so, we will pad the
|
|
|
6d394f |
- * block, process it, and then continue padding into a second
|
|
|
6d394f |
- * block.
|
|
|
6d394f |
- */
|
|
|
6d394f |
- if (context->Message_Block_Index > 55) {
|
|
|
6d394f |
- context->Message_Block[context->Message_Block_Index++] = 0x80;
|
|
|
6d394f |
- while(context->Message_Block_Index < 64) {
|
|
|
6d394f |
- context->Message_Block[context->Message_Block_Index++] = 0;
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- SHA1ProcessMessageBlock(context);
|
|
|
6d394f |
-
|
|
|
6d394f |
- while(context->Message_Block_Index < 56) {
|
|
|
6d394f |
- context->Message_Block[context->Message_Block_Index++] = 0;
|
|
|
6d394f |
- }
|
|
|
6d394f |
- } else {
|
|
|
6d394f |
- context->Message_Block[context->Message_Block_Index++] = 0x80;
|
|
|
6d394f |
- while(context->Message_Block_Index < 56) {
|
|
|
6d394f |
-
|
|
|
6d394f |
- context->Message_Block[context->Message_Block_Index++] = 0;
|
|
|
6d394f |
- }
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- /*
|
|
|
6d394f |
- * Store the message length as the last 8 octets
|
|
|
6d394f |
- */
|
|
|
6d394f |
- context->Message_Block[56] = context->Length_High >> 24;
|
|
|
6d394f |
- context->Message_Block[57] = context->Length_High >> 16;
|
|
|
6d394f |
- context->Message_Block[58] = context->Length_High >> 8;
|
|
|
6d394f |
- context->Message_Block[59] = context->Length_High;
|
|
|
6d394f |
- context->Message_Block[60] = context->Length_Low >> 24;
|
|
|
6d394f |
- context->Message_Block[61] = context->Length_Low >> 16;
|
|
|
6d394f |
- context->Message_Block[62] = context->Length_Low >> 8;
|
|
|
6d394f |
- context->Message_Block[63] = context->Length_Low;
|
|
|
6d394f |
-
|
|
|
6d394f |
- SHA1ProcessMessageBlock(context);
|
|
|
6d394f |
-}
|
|
|
6d394f |
-
|
|
|
6d394f |
-#ifdef TEST_DRIVER
|
|
|
6d394f |
-
|
|
|
6d394f |
-/*
|
|
|
6d394f |
- * sha1test.c
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Description:
|
|
|
6d394f |
- * This file will exercise the SHA-1 code performing the three
|
|
|
6d394f |
- * tests documented in FIPS PUB 180-1 plus one which calls
|
|
|
6d394f |
- * SHA1Input with an exact multiple of 512 bits, plus a few
|
|
|
6d394f |
- * error test checks.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Portability Issues:
|
|
|
6d394f |
- * None.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- */
|
|
|
6d394f |
-
|
|
|
6d394f |
-#include <stdint.h>
|
|
|
6d394f |
-#include <stdio.h>
|
|
|
6d394f |
-#include <string.h>
|
|
|
6d394f |
-#include "sha1.h"
|
|
|
6d394f |
-
|
|
|
6d394f |
-/*
|
|
|
6d394f |
- * Define patterns for testing
|
|
|
6d394f |
- */
|
|
|
6d394f |
-#define TEST1 "abc"
|
|
|
6d394f |
-#define TEST2a "abcdbcdecdefdefgefghfghighijhi"
|
|
|
6d394f |
-
|
|
|
6d394f |
-#define TEST2b "jkijkljklmklmnlmnomnopnopq"
|
|
|
6d394f |
-#define TEST2 TEST2a TEST2b
|
|
|
6d394f |
-#define TEST3 "a"
|
|
|
6d394f |
-#define TEST4a "01234567012345670123456701234567"
|
|
|
6d394f |
-#define TEST4b "01234567012345670123456701234567"
|
|
|
6d394f |
- /* an exact multiple of 512 bits */
|
|
|
6d394f |
-#define TEST4 TEST4a TEST4b
|
|
|
6d394f |
-char *testarray[4] =
|
|
|
6d394f |
-{
|
|
|
6d394f |
- TEST1,
|
|
|
6d394f |
- TEST2,
|
|
|
6d394f |
- TEST3,
|
|
|
6d394f |
- TEST4
|
|
|
6d394f |
-};
|
|
|
6d394f |
-long int repeatcount[4] = { 1, 1, 1000000, 10 };
|
|
|
6d394f |
-char *resultarray[4] =
|
|
|
6d394f |
-{
|
|
|
6d394f |
- "A9 99 3E 36 47 06 81 6A BA 3E 25 71 78 50 C2 6C 9C D0 D8 9D",
|
|
|
6d394f |
- "84 98 3E 44 1C 3B D2 6E BA AE 4A A1 F9 51 29 E5 E5 46 70 F1",
|
|
|
6d394f |
- "34 AA 97 3C D4 C4 DA A4 F6 1E EB 2B DB AD 27 31 65 34 01 6F",
|
|
|
6d394f |
- "DE A3 56 A2 CD DD 90 C7 A7 EC ED C5 EB B5 63 93 4F 46 04 52"
|
|
|
6d394f |
-};
|
|
|
6d394f |
-
|
|
|
6d394f |
-int main()
|
|
|
6d394f |
-{
|
|
|
6d394f |
- SHA1Context sha;
|
|
|
6d394f |
- int i, j, err;
|
|
|
6d394f |
- uint8_t Message_Digest[20];
|
|
|
6d394f |
-
|
|
|
6d394f |
- /*
|
|
|
6d394f |
- * Perform SHA-1 tests
|
|
|
6d394f |
- */
|
|
|
6d394f |
- for(j = 0; j < 4; ++j) {
|
|
|
6d394f |
- printf( "\nTest %d: %d, '%s'\n",
|
|
|
6d394f |
- j+1,
|
|
|
6d394f |
- repeatcount[j],
|
|
|
6d394f |
- testarray[j]);
|
|
|
6d394f |
-
|
|
|
6d394f |
- err = SHA1Init(&sha);
|
|
|
6d394f |
- if (err) {
|
|
|
6d394f |
- fprintf(stderr, "SHA1Reset Error %d.\n", err );
|
|
|
6d394f |
- break; /* out of for j loop */
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- for(i = 0; i < repeatcount[j]; ++i) {
|
|
|
6d394f |
-
|
|
|
6d394f |
- err = SHA1Input(&sha,
|
|
|
6d394f |
- (const unsigned char *) testarray[j],
|
|
|
6d394f |
- strlen(testarray[j]));
|
|
|
6d394f |
- if (err) {
|
|
|
6d394f |
- fprintf(stderr, "SHA1Input Error %d.\n", err );
|
|
|
6d394f |
- break; /* out of for i loop */
|
|
|
6d394f |
- }
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- err = SHA1Final(&sha, Message_Digest);
|
|
|
6d394f |
- if (err) {
|
|
|
6d394f |
- fprintf(stderr,
|
|
|
6d394f |
- "SHA1Result Error %d, could not compute message digest.\n",
|
|
|
6d394f |
- err );
|
|
|
6d394f |
- }
|
|
|
6d394f |
- else
|
|
|
6d394f |
- {
|
|
|
6d394f |
- printf("\t");
|
|
|
6d394f |
- for(i = 0; i < 20 ; ++i) {
|
|
|
6d394f |
- printf("%02X ", Message_Digest[i]);
|
|
|
6d394f |
- }
|
|
|
6d394f |
- printf("\n");
|
|
|
6d394f |
- }
|
|
|
6d394f |
- printf("Should match:\n");
|
|
|
6d394f |
- printf("\t%s\n", resultarray[j]);
|
|
|
6d394f |
- }
|
|
|
6d394f |
-
|
|
|
6d394f |
- /* Test some error returns */
|
|
|
6d394f |
- err = SHA1Input(&sha,(const unsigned char *) testarray[1], 1);
|
|
|
6d394f |
- printf ("\nError %d. Should be %d.\n", err, shaStateError );
|
|
|
6d394f |
- err = SHA1Init(0);
|
|
|
6d394f |
- printf ("\nError %d. Should be %d.\n", err, shaNull );
|
|
|
6d394f |
- return 0;
|
|
|
6d394f |
-}
|
|
|
6d394f |
-
|
|
|
6d394f |
-#endif /* TEST_DRIVER */
|
|
|
6d394f |
-
|
|
|
6d394f |
-#ifdef SHA1_SUM
|
|
|
6d394f |
-/*
|
|
|
6d394f |
- * Reads a single ASCII file and prints the HEX sha1 sum.
|
|
|
6d394f |
- */
|
|
|
6d394f |
-#include <stdio.h>
|
|
|
6d394f |
-int main(int argc, char *argv[])
|
|
|
6d394f |
-{
|
|
|
6d394f |
- FILE *fd;
|
|
|
6d394f |
- SHA1Context ctx;
|
|
|
6d394f |
- char buf[5000];
|
|
|
6d394f |
- char signature[25];
|
|
|
6d394f |
-
|
|
|
6d394f |
- if (argc < 1) {
|
|
|
6d394f |
- printf("Must have filename\n");
|
|
|
6d394f |
- exit(1);
|
|
|
6d394f |
- }
|
|
|
6d394f |
- fd = fopen(argv[1], "rb");
|
|
|
6d394f |
- if (!fd) {
|
|
|
6d394f |
- berrno be;
|
|
|
6d394f |
- printf("Could not open %s: ERR=%s\n", argv[1], be.bstrerror(errno));
|
|
|
6d394f |
- exit(1);
|
|
|
6d394f |
- }
|
|
|
6d394f |
- SHA1Init(&ctx;;
|
|
|
6d394f |
- while (fgets(buf, sizeof(buf), fd)) {
|
|
|
6d394f |
- SHA1Update(&ctx, (unsigned char *)buf, strlen(buf));
|
|
|
6d394f |
- }
|
|
|
6d394f |
- SHA1Final(&ctx, (unsigned char *)signature);
|
|
|
6d394f |
- for (int i=0; i < 20; i++) {
|
|
|
6d394f |
- printf("%02x", signature[i]& 0xFF);
|
|
|
6d394f |
- }
|
|
|
6d394f |
- printf(" %s\n", argv[1]);
|
|
|
6d394f |
- fclose(fd);
|
|
|
6d394f |
-}
|
|
|
6d394f |
-#endif
|
|
|
6d394f |
diff -Naur bacula-9.0.0.old/src/lib/sha1.h bacula-9.0.0/src/lib/sha1.h
|
|
|
6d394f |
--- bacula-9.0.0.old/src/lib/sha1.h 2017-07-10 08:52:38.928834471 +0200
|
|
|
6d394f |
+++ bacula-9.0.0/src/lib/sha1.h 1970-01-01 01:00:00.000000000 +0100
|
|
|
6d394f |
@@ -1,107 +0,0 @@
|
|
|
6d394f |
-/*
|
|
|
6d394f |
- * sha1.h
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Description:
|
|
|
6d394f |
- * This is the header file for code which implements the Secure
|
|
|
6d394f |
- * Hashing Algorithm 1 as defined in FIPS PUB 180-1 published
|
|
|
6d394f |
- * April 17, 1995.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Many of the variable names in this code, especially the
|
|
|
6d394f |
- * single character names, were used because those were the names
|
|
|
6d394f |
- * used in the publication.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Please read the file sha1.c for more information.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Full Copyright Statement
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Copyright (C) The Internet Society (2001). All Rights Reserved.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * This document and translations of it may be copied and furnished to
|
|
|
6d394f |
- * others, and derivative works that comment on or otherwise explain it
|
|
|
6d394f |
- * or assist in its implementation may be prepared, copied, published
|
|
|
6d394f |
- * and distributed, in whole or in part, without restriction of any
|
|
|
6d394f |
- * kind, provided that the above copyright notice and this paragraph are
|
|
|
6d394f |
- * included on all such copies and derivative works. However, this
|
|
|
6d394f |
- * document itself may not be modified in any way, such as by removing
|
|
|
6d394f |
- * the copyright notice or references to the Internet Society or other
|
|
|
6d394f |
- * Internet organizations, except as needed for the purpose of
|
|
|
6d394f |
- * developing Internet standards in which case the procedures for
|
|
|
6d394f |
- * copyrights defined in the Internet Standards process must be
|
|
|
6d394f |
- * followed, or as required to translate it into languages other than
|
|
|
6d394f |
- * English.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * The limited permissions granted above are perpetual and will not be
|
|
|
6d394f |
- * revoked by the Internet Society or its successors or assigns.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * This document and the information contained herein is provided on an
|
|
|
6d394f |
- * "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
|
|
|
6d394f |
- * TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
|
|
|
6d394f |
- * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
|
|
|
6d394f |
- * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
|
|
|
6d394f |
- * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Acknowledgement
|
|
|
6d394f |
- *
|
|
|
6d394f |
- * Funding for the RFC Editor function is currently provided by the
|
|
|
6d394f |
- * Internet Society.
|
|
|
6d394f |
- *
|
|
|
6d394f |
- */
|
|
|
6d394f |
-
|
|
|
6d394f |
-#ifndef _SHA1_H_
|
|
|
6d394f |
-#define _SHA1_H_
|
|
|
6d394f |
-
|
|
|
6d394f |
-#include "bacula.h"
|
|
|
6d394f |
-
|
|
|
6d394f |
-/*
|
|
|
6d394f |
- * If you do not have the ISO standard stdint.h header file, then you
|
|
|
6d394f |
- * must typdef the following:
|
|
|
6d394f |
- * name meaning
|
|
|
6d394f |
- * uint32_t unsigned 32 bit integer
|
|
|
6d394f |
- * uint8_t unsigned 8 bit integer (i.e., unsigned char)
|
|
|
6d394f |
- * int32_t integer of 32 bits
|
|
|
6d394f |
- *
|
|
|
6d394f |
- */
|
|
|
6d394f |
-
|
|
|
6d394f |
-#ifndef _SHA_enum_
|
|
|
6d394f |
-#define _SHA_enum_
|
|
|
6d394f |
-enum
|
|
|
6d394f |
-{
|
|
|
6d394f |
- shaSuccess = 0,
|
|
|
6d394f |
- shaNull, /* Null pointer parameter */
|
|
|
6d394f |
- shaInputTooLong, /* input data too long */
|
|
|
6d394f |
- shaStateError /* called Input after Result */
|
|
|
6d394f |
-};
|
|
|
6d394f |
-#endif
|
|
|
6d394f |
-#define SHA1HashSize 20
|
|
|
6d394f |
-
|
|
|
6d394f |
-/*
|
|
|
6d394f |
- * This structure will hold context information for the SHA-1
|
|
|
6d394f |
- * hashing operation
|
|
|
6d394f |
- */
|
|
|
6d394f |
-typedef struct SHA1Context
|
|
|
6d394f |
-{
|
|
|
6d394f |
- uint32_t Intermediate_Hash[SHA1HashSize/4]; /* Message Digest */
|
|
|
6d394f |
-
|
|
|
6d394f |
- uint32_t Length_Low; /* Message length in bits */
|
|
|
6d394f |
- uint32_t Length_High; /* Message length in bits */
|
|
|
6d394f |
-
|
|
|
6d394f |
- /* Index into message block array */
|
|
|
6d394f |
- int32_t Message_Block_Index;
|
|
|
6d394f |
- uint8_t Message_Block[64]; /* 512-bit message blocks */
|
|
|
6d394f |
-
|
|
|
6d394f |
- int Computed; /* Is the digest computed? */
|
|
|
6d394f |
- int Corrupted; /* Is the message digest corrupted? */
|
|
|
6d394f |
-} SHA1Context;
|
|
|
6d394f |
-
|
|
|
6d394f |
-/*
|
|
|
6d394f |
- * Function Prototypes
|
|
|
6d394f |
- */
|
|
|
6d394f |
-
|
|
|
6d394f |
-int SHA1Init(SHA1Context *);
|
|
|
6d394f |
-int SHA1Update(SHA1Context *,
|
|
|
6d394f |
- const uint8_t *,
|
|
|
6d394f |
- unsigned int);
|
|
|
6d394f |
-int SHA1Final(SHA1Context *,
|
|
|
6d394f |
- uint8_t Message_Digest[SHA1HashSize]);
|
|
|
6d394f |
-
|
|
|
6d394f |
-#endif
|