Ticket #619: nALFS-md5-2.patch
File nALFS-md5-2.patch, 21.0 KB (added by , 21 years ago) |
---|
-
Rules.mak.in
diff -X /usr/src/dontdiff -urN nALFS/Rules.mak.in nALFS-new/Rules.mak.in
old new 38 38 INSTALL := @INSTALL@ 39 39 40 40 CC := @CC@ 41 LD := @LD@ 42 AR := @AR@ 43 RANLIB := @RANLIB@ 41 44 42 45 CPPFLAGS := @CPPFLAGS@ 43 46 CFLAGS := @CFLAGS@ 44 47 LDFLAGS := @LDFLAGS@ 45 48 LDLIBS := @LIBS@ 46 49 50 NALFS_LIB := $(top_builddir)/src/lib/lib.a 47 51 48 52 handlers_directory := $(libdir)/nALFS/ 49 53 50 54 CPPFLAGS += -DHANDLERS_DIRECTORY=\"$(handlers_directory)\" 51 CPPFLAGS += -I$(abs_top_srcdir)/src/ 55 CPPFLAGS += -I$(abs_top_srcdir)/src/ -I$(abs_top_srcdir)/src/lib/ 52 56 53 57 CFLAGS += -W -Wall -Wshadow -Winline 54 58 55 56 59 C_FILES := $(wildcard $(srcdir)/*.c) 57 60 H_FILES := $(wildcard $(srcdir)/*.h) 58 61 O_FILES := $(patsubst $(srcdir)/%.c,%.o, $(C_FILES)) -
configure.in
diff -X /usr/src/dontdiff -urN nALFS/configure.in nALFS-new/configure.in
old new 28 28 AC_PROG_CC 29 29 AC_PROG_INSTALL 30 30 31 AC_CHECK_TOOL(AR, ar) 32 AC_CHECK_TOOL(LD, ld) 33 AC_CHECK_TOOL(RANLIB, ranlib, :) 31 34 32 35 AC_CHECK_LIB(ncurses, initscr) 33 36 AC_CHECK_LIB(form, form_driver) … … 66 69 67 70 AC_ARG_WITH(ssl, 68 71 [ --with-ssl=PREFIX specify prefix for ssl files (ssl will be used 69 for checking MD5 digest in <unpack>)],72 for checking non-MD5 digests in <unpack> elements)], 70 73 [ 71 74 case "$withval" in 72 75 n|no) 73 disable_ssl=yes74 76 ;; 75 77 y|ye|yes) 78 enable_ssl=yes 76 79 ;; 77 78 80 *) 79 81 LIBS="$LIBS -L$withval/lib" 82 enable_ssl=yes 80 83 ;; 81 84 esac 82 85 ]) 83 86 84 if test "$ disable_ssl" != "yes" ; then87 if test "$enable_ssl" == "yes" ; then 85 88 AC_CHECK_LIB(ssl, OpenSSL_add_all_digests, [ 86 89 CPPFLAGS="$CPPFLAGS -DHAVE_LIBSSL" 87 90 LIBS="$LIBS -lcrypto -lssl"]) … … 130 133 Rules.mak 131 134 Makefile 132 135 src/Makefile 136 src/lib/Makefile 133 137 src/handlers/Makefile 134 138 ]) -
src/Makefile.in
diff -X /usr/src/dontdiff -urN nALFS/src/Makefile.in nALFS-new/src/Makefile.in
old new 29 29 LDFLAGS += -Wl,-export-dynamic 30 30 31 31 32 .PHONY: all handlers32 .PHONY: all $(NALFS_LIB) handlers 33 33 34 all: handlers nALFS 34 all: $(NALFS_LIB) handlers nALFS 35 36 $(NALFS_LIB): 37 @make -C lib 35 38 36 39 handlers: 37 40 @make -C handlers 38 41 39 nALFS: $(O_FILES) 42 nALFS: $(O_FILES) $(NALFS_LIB) 40 43 $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ 41 44 42 45 $(O_FILES): %.o: $(srcdir)/%.c … … 46 49 .PHONY: clean distclean 47 50 48 51 clean: 52 @make -C lib clean 49 53 @make -C handlers clean 50 54 $(RM) $(O_FILES) nALFS 51 55 52 56 distclean: 57 @make -C lib distclean 53 58 @make -C handlers distclean 54 59 $(RM) Makefile -
src/handlers/Makefile.in
diff -X /usr/src/dontdiff -urN nALFS/src/handlers/Makefile.in nALFS-new/src/handlers/Makefile.in
old new 28 28 29 29 CFLAGS += -fPIC -shared 30 30 31 SO_FILES = $(patsubst $(srcdir)/%.c,%.so, $(C_FILES)) 32 31 SO_FILES := $(patsubst $(srcdir)/%.c,%.so, $(C_FILES)) 33 32 34 33 .PHONY: all 35 34 36 all: $(SO_FILES) 37 38 $(SO_FILES): %.so: $(srcdir)/%.c 39 $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ 35 all: $(NALFS_LIB) $(SO_FILES) 40 36 37 $(SO_FILES): %.so: $(srcdir)/%.c $(NALFS_LIB) 38 $(CC) $(CFLAGS) $(CPPFLAGS) $^ -o $@ 41 39 42 40 .PHONY: clean distclean 43 41 -
src/handlers/new-unpack.c
diff -X /usr/src/dontdiff -urN nALFS/src/handlers/new-unpack.c nALFS-new/src/handlers/new-unpack.c
old new 36 36 #include "nalfs.h" 37 37 #include "backend.h" 38 38 #include "config.h" 39 #include "digest.h" 39 40 40 41 41 42 #define El_unpack_reference(el) alloc_trimmed_param_value("reference", el) 42 43 #define El_unpack_archive(el) alloc_trimmed_param_value("archive", el) 43 44 #define El_unpack_destination(el) alloc_trimmed_param_value("destination", el) 45 #define El_unpack_digest(el) alloc_trimmed_param_value("digest", el) 44 46 45 47 46 48 typedef enum extension_e { 47 49 GZ, TAR_GZ, TGZ, BZ2, TAR_BZ2, TAR, ZIP, TAR_Z, Z, UNKNOWN 48 50 } extension_e; 49 51 50 51 #ifdef HAVE_LIBSSL52 53 #define El_unpack_digest(el) alloc_trimmed_param_value("digest", el)54 55 #include <openssl/evp.h>56 57 int verify_digest(char* type, char* digest, char* file)58 {59 EVP_MD_CTX ctx;60 const EVP_MD *md;61 char buffer[4094];62 FILE *istream;63 unsigned char md_value[EVP_MAX_MD_SIZE];64 char md_value_hex[2*EVP_MAX_MD_SIZE + 1 ];65 unsigned int md_len;66 int i;67 char *s;68 69 70 OpenSSL_add_all_digests();71 72 md = EVP_get_digestbyname(type);73 74 EVP_DigestInit(&ctx, md);75 76 istream = fopen(file, "r");77 if (istream) {78 size_t nbbytes;79 80 while ((nbbytes = fread(&buffer[0], 1, sizeof(buffer), istream)) != 0) {81 EVP_DigestUpdate(&ctx, &buffer[0], nbbytes);82 }83 84 fclose(istream);85 86 EVP_DigestFinal(&ctx, &md_value[0], &md_len);87 88 89 for(i = 0, s = &md_value_hex[0]; i < (int)md_len; s += 2, ++i) {90 sprintf(s, "%02x", md_value[i]);91 }92 *s = 0;93 94 if (! strcmp(digest, &md_value_hex[0])) {95 Nprint("Digest ok.");96 return 0;97 }98 99 Nprint_err("Expected digest : %s", digest);100 Nprint_err("Found digest : %s", &md_value_hex[0]);101 102 } else {103 Nprint_err(104 "Unable to open the archive when checking digest: %s", file);105 }106 107 return -1;108 }109 110 #endif111 112 113 52 #ifdef HAVE_LIBCURL 114 53 115 54 typedef struct output_file_s { … … 262 201 char *handler_syntax_versions[] = { "3.0", "3.1", NULL }; 263 202 // char *handler_attributes[] = { NULL }; 264 203 char *handler_parameters[] = 265 #ifdef HAVE_LIBSSL266 204 { "digest", "reference", "archive", "destination", NULL }; 267 #else268 { "reference", "archive", "destination", NULL };269 #endif270 205 int handler_action = 1; 271 206 272 207 … … 276 211 char *base_name; 277 212 char *archive; 278 213 char *destination; 279 #ifdef HAVE_LIBSSL280 214 char *digest; 281 #endif282 215 struct stat file_stat; 283 216 extension_e extension = UNKNOWN; 284 217 … … 326 259 } 327 260 } 328 261 329 #ifdef HAVE_LIBSSL330 262 if ((digest = El_unpack_digest(el)) != NULL) { 331 263 element_s *el2 = first_param("digest", el); 332 264 char *type = attr_value("type", el2); … … 351 283 return -1; 352 284 } 353 285 } 354 #endif355 286 356 287 /* Watch for the order! */ 357 288 if (! (strncmp(archive + strlen(archive) - 7, ".tar.gz", 7))) -
src/lib/Makefile.in
diff -X /usr/src/dontdiff -urN nALFS/src/lib/Makefile.in nALFS-new/src/lib/Makefile.in
old new 1 # 2 # Makefile - Makefile for common code library. 3 # 4 # Copyright (C) 2001-2003 5 # 6 # Neven Has <haski@sezampro.yu> and 7 # Kevin P. Fleming <kpfleming@backtobasicsmgmt.com> 8 # 9 # This program is free software; you can redistribute it and/or modify 10 # it under the terms of the GNU General Public License as published by 11 # the Free Software Foundation; either version 2 of the License, or 12 # (at your option) any later version. 13 # 14 # This program is distributed in the hope that it will be useful, 15 # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 # GNU General Public License for more details. 18 # 19 # You should have received a copy of the GNU General Public License 20 # along with this program; if not, write to the Free Software 21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 # 23 24 srcdir := @top_srcdir@/src/lib 25 top_builddir := @top_builddir@ 26 include $(top_builddir)/Rules.mak 27 28 .PHONY: all 29 30 all: $(NALFS_LIB) 31 32 $(NALFS_LIB): $(O_FILES) 33 $(AR) cr $@ $^ 34 $(RANLIB) $@ 35 36 $(O_FILES): %.o: $(srcdir)/%.c 37 $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ 38 39 .PHONY: clean distclean 40 41 clean: 42 $(RM) $(O_FILES) $(NALFS_LIB) 43 44 distclean: 45 $(RM) Makefile -
src/lib/digest.c
diff -X /usr/src/dontdiff -urN nALFS/src/lib/digest.c nALFS-new/src/lib/digest.c
old new 1 /* 2 * digest.c - Verify a file's contents have not been changed. 3 * 4 * Copyright (C) 2001-2003 5 * 6 * Neven Has <haski@sezampro.yu> and 7 * Kevin P. Fleming <kpfleming@backtobasicsmgmt.com> 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 */ 23 24 25 #include <stdlib.h> 26 #include <string.h> 27 #include <unistd.h> 28 #include <errno.h> 29 #include <ctype.h> 30 #include <sys/types.h> 31 32 #ifdef HAVE_LIBSSL 33 34 #include <openssl/evp.h> 35 #define MAX_MD_SIZE EVP_MAX_MD_SIZE 36 37 #else /* !HAVE_LIBSSL */ 38 39 #define MAX_MD_SIZE 16 40 41 #endif /* HAVE_LIBSSL */ 42 43 #include "win.h" 44 #include "md5.h" 45 46 int verify_digest(const char* type, char* digest, const char* file) 47 { 48 char buffer[4094]; 49 FILE *istream; 50 unsigned int i; 51 unsigned int md_len = 0; 52 unsigned char md_value[MAX_MD_SIZE]; 53 char md_value_hex[2*MAX_MD_SIZE + 1 ]; 54 int use_ssl; 55 56 struct md5_context md5_ctx; 57 58 #ifdef HAVE_LIBSSL 59 EVP_MD_CTX ssl_ctx; 60 const EVP_MD *ssl_md; 61 #endif /* HAVE_LIBSSL */ 62 63 use_ssl = strncmp(type, "md5", 3); 64 65 if (!use_ssl) { 66 md5_starts(&md5_ctx); 67 } else { 68 #ifdef HAVE_LIBSSL 69 OpenSSL_add_all_digests(); 70 ssl_md = EVP_get_digestbyname(type); 71 if (ssl_md) 72 EVP_DigestInit(&ssl_ctx, ssl_md); 73 else { 74 Nprint_err("SSL does not support %s digest", type); 75 return -1; 76 } 77 #else /* !HAVE_LIBSSL */ 78 Nprint_err("Only MD5 digest supported without SSL"); 79 return -1; 80 #endif /* HAVE_LIBSSL */ 81 } 82 83 istream = fopen(file, "r"); 84 if (istream) { 85 size_t nbbytes; 86 87 while ((nbbytes = fread(&buffer[0], 1, sizeof(buffer), istream)) != 0) { 88 if (!use_ssl) 89 md5_update(&md5_ctx, &buffer[0], nbbytes); 90 #ifdef HAVE_LIBSSL 91 else 92 EVP_DigestUpdate(&ssl_ctx, &buffer[0], nbbytes); 93 #endif /* HAVE_LIBSSL */ 94 } 95 96 if (!use_ssl) { 97 md5_finish(&md5_ctx, &md_value[0]); 98 md_len = 16; 99 } 100 #ifdef HAVE_LIBSSL 101 else 102 EVP_DigestFinal(&ssl_ctx, &md_value[0], &md_len); 103 #endif /* HAVE_LIBSSL */ 104 105 fclose(istream); 106 107 for(i = 0; i < md_len; i++) 108 sprintf(&md_value_hex[0] + i * 2, "%02x", md_value[i]); 109 110 if (! strcmp(digest, &md_value_hex[0])) { 111 Nprint("Digest ok."); 112 return 0; 113 } 114 115 Nprint_err("Expected digest : %s", digest); 116 Nprint_err("Found digest : %s", &md_value_hex[0]); 117 118 } else { 119 Nprint_err( 120 "Unable to open the archive when checking digest: %s", file); 121 } 122 123 return -1; 124 } -
src/lib/digest.h
diff -X /usr/src/dontdiff -urN nALFS/src/lib/digest.h nALFS-new/src/lib/digest.h
old new 1 /* 2 * digest.h - Verify a file's contents have not been changed. 3 * 4 * Copyright (C) 2003-2003 5 * 6 * Neven Has <haski@sezampro.yu> and 7 * Kevin P. Fleming <kpfleming@backtobasicsmgmt.com> 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 */ 23 24 #ifndef _DIGEST_H 25 #define _DIGEST_H 26 27 extern int verify_digest(const char *type, char *digest, const char *file); 28 29 #endif /* _DIGEST_H */ -
src/lib/md5.c
diff -X /usr/src/dontdiff -urN nALFS/src/lib/md5.c nALFS-new/src/lib/md5.c
old new 1 /* 2 * md5.c - MD5 (RFC 1321) sum computation. 3 * 4 * Copyright (C) 2001-2003 5 * 6 * Christophe Devine <devine@cr0.net> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 */ 22 23 #include <string.h> 24 #include "md5.h" 25 26 #define GET_UINT32(n,b,i) \ 27 { \ 28 (n) = ( (uint32) (b)[(i) + 3] << 24 ) \ 29 | ( (uint32) (b)[(i) + 2] << 16 ) \ 30 | ( (uint32) (b)[(i) + 1] << 8 ) \ 31 | ( (uint32) (b)[(i) ] ); \ 32 } 33 34 #define PUT_UINT32(n,b,i) \ 35 { \ 36 (b)[(i) ] = (uint8) ( (n) ); \ 37 (b)[(i) + 1] = (uint8) ( (n) >> 8 ); \ 38 (b)[(i) + 2] = (uint8) ( (n) >> 16 ); \ 39 (b)[(i) + 3] = (uint8) ( (n) >> 24 ); \ 40 } 41 42 void md5_starts( struct md5_context *ctx ) 43 { 44 ctx->total[0] = 0; 45 ctx->total[1] = 0; 46 ctx->state[0] = 0x67452301; 47 ctx->state[1] = 0xEFCDAB89; 48 ctx->state[2] = 0x98BADCFE; 49 ctx->state[3] = 0x10325476; 50 } 51 52 void md5_process( struct md5_context *ctx, uint8 data[64] ) 53 { 54 uint32 A, B, C, D, X[16]; 55 56 GET_UINT32( X[0], data, 0 ); 57 GET_UINT32( X[1], data, 4 ); 58 GET_UINT32( X[2], data, 8 ); 59 GET_UINT32( X[3], data, 12 ); 60 GET_UINT32( X[4], data, 16 ); 61 GET_UINT32( X[5], data, 20 ); 62 GET_UINT32( X[6], data, 24 ); 63 GET_UINT32( X[7], data, 28 ); 64 GET_UINT32( X[8], data, 32 ); 65 GET_UINT32( X[9], data, 36 ); 66 GET_UINT32( X[10], data, 40 ); 67 GET_UINT32( X[11], data, 44 ); 68 GET_UINT32( X[12], data, 48 ); 69 GET_UINT32( X[13], data, 52 ); 70 GET_UINT32( X[14], data, 56 ); 71 GET_UINT32( X[15], data, 60 ); 72 73 #define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) 74 75 #define P(a,b,c,d,k,s,t) \ 76 { \ 77 a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \ 78 } 79 80 A = ctx->state[0]; 81 B = ctx->state[1]; 82 C = ctx->state[2]; 83 D = ctx->state[3]; 84 85 #define F(x,y,z) (z ^ (x & (y ^ z))) 86 87 P( A, B, C, D, 0, 7, 0xD76AA478 ); 88 P( D, A, B, C, 1, 12, 0xE8C7B756 ); 89 P( C, D, A, B, 2, 17, 0x242070DB ); 90 P( B, C, D, A, 3, 22, 0xC1BDCEEE ); 91 P( A, B, C, D, 4, 7, 0xF57C0FAF ); 92 P( D, A, B, C, 5, 12, 0x4787C62A ); 93 P( C, D, A, B, 6, 17, 0xA8304613 ); 94 P( B, C, D, A, 7, 22, 0xFD469501 ); 95 P( A, B, C, D, 8, 7, 0x698098D8 ); 96 P( D, A, B, C, 9, 12, 0x8B44F7AF ); 97 P( C, D, A, B, 10, 17, 0xFFFF5BB1 ); 98 P( B, C, D, A, 11, 22, 0x895CD7BE ); 99 P( A, B, C, D, 12, 7, 0x6B901122 ); 100 P( D, A, B, C, 13, 12, 0xFD987193 ); 101 P( C, D, A, B, 14, 17, 0xA679438E ); 102 P( B, C, D, A, 15, 22, 0x49B40821 ); 103 104 #undef F 105 106 #define F(x,y,z) (y ^ (z & (x ^ y))) 107 108 P( A, B, C, D, 1, 5, 0xF61E2562 ); 109 P( D, A, B, C, 6, 9, 0xC040B340 ); 110 P( C, D, A, B, 11, 14, 0x265E5A51 ); 111 P( B, C, D, A, 0, 20, 0xE9B6C7AA ); 112 P( A, B, C, D, 5, 5, 0xD62F105D ); 113 P( D, A, B, C, 10, 9, 0x02441453 ); 114 P( C, D, A, B, 15, 14, 0xD8A1E681 ); 115 P( B, C, D, A, 4, 20, 0xE7D3FBC8 ); 116 P( A, B, C, D, 9, 5, 0x21E1CDE6 ); 117 P( D, A, B, C, 14, 9, 0xC33707D6 ); 118 P( C, D, A, B, 3, 14, 0xF4D50D87 ); 119 P( B, C, D, A, 8, 20, 0x455A14ED ); 120 P( A, B, C, D, 13, 5, 0xA9E3E905 ); 121 P( D, A, B, C, 2, 9, 0xFCEFA3F8 ); 122 P( C, D, A, B, 7, 14, 0x676F02D9 ); 123 P( B, C, D, A, 12, 20, 0x8D2A4C8A ); 124 125 #undef F 126 127 #define F(x,y,z) (x ^ y ^ z) 128 129 P( A, B, C, D, 5, 4, 0xFFFA3942 ); 130 P( D, A, B, C, 8, 11, 0x8771F681 ); 131 P( C, D, A, B, 11, 16, 0x6D9D6122 ); 132 P( B, C, D, A, 14, 23, 0xFDE5380C ); 133 P( A, B, C, D, 1, 4, 0xA4BEEA44 ); 134 P( D, A, B, C, 4, 11, 0x4BDECFA9 ); 135 P( C, D, A, B, 7, 16, 0xF6BB4B60 ); 136 P( B, C, D, A, 10, 23, 0xBEBFBC70 ); 137 P( A, B, C, D, 13, 4, 0x289B7EC6 ); 138 P( D, A, B, C, 0, 11, 0xEAA127FA ); 139 P( C, D, A, B, 3, 16, 0xD4EF3085 ); 140 P( B, C, D, A, 6, 23, 0x04881D05 ); 141 P( A, B, C, D, 9, 4, 0xD9D4D039 ); 142 P( D, A, B, C, 12, 11, 0xE6DB99E5 ); 143 P( C, D, A, B, 15, 16, 0x1FA27CF8 ); 144 P( B, C, D, A, 2, 23, 0xC4AC5665 ); 145 146 #undef F 147 148 #define F(x,y,z) (y ^ (x | ~z)) 149 150 P( A, B, C, D, 0, 6, 0xF4292244 ); 151 P( D, A, B, C, 7, 10, 0x432AFF97 ); 152 P( C, D, A, B, 14, 15, 0xAB9423A7 ); 153 P( B, C, D, A, 5, 21, 0xFC93A039 ); 154 P( A, B, C, D, 12, 6, 0x655B59C3 ); 155 P( D, A, B, C, 3, 10, 0x8F0CCC92 ); 156 P( C, D, A, B, 10, 15, 0xFFEFF47D ); 157 P( B, C, D, A, 1, 21, 0x85845DD1 ); 158 P( A, B, C, D, 8, 6, 0x6FA87E4F ); 159 P( D, A, B, C, 15, 10, 0xFE2CE6E0 ); 160 P( C, D, A, B, 6, 15, 0xA3014314 ); 161 P( B, C, D, A, 13, 21, 0x4E0811A1 ); 162 P( A, B, C, D, 4, 6, 0xF7537E82 ); 163 P( D, A, B, C, 11, 10, 0xBD3AF235 ); 164 P( C, D, A, B, 2, 15, 0x2AD7D2BB ); 165 P( B, C, D, A, 9, 21, 0xEB86D391 ); 166 167 #undef F 168 169 ctx->state[0] += A; 170 ctx->state[1] += B; 171 ctx->state[2] += C; 172 ctx->state[3] += D; 173 } 174 175 void md5_update( struct md5_context *ctx, uint8 *input, uint32 length ) 176 { 177 uint32 left, fill; 178 179 if( ! length ) return; 180 181 left = ( ctx->total[0] >> 3 ) & 0x3F; 182 fill = 64 - left; 183 184 ctx->total[0] += length << 3; 185 ctx->total[1] += length >> 29; 186 187 ctx->total[0] &= 0xFFFFFFFF; 188 ctx->total[1] += ctx->total[0] < ( length << 3 ); 189 190 if( left && length >= fill ) 191 { 192 memcpy( (void *) (ctx->buffer + left), (void *) input, fill ); 193 md5_process( ctx, ctx->buffer ); 194 length -= fill; 195 input += fill; 196 left = 0; 197 } 198 199 while( length >= 64 ) 200 { 201 md5_process( ctx, input ); 202 length -= 64; 203 input += 64; 204 } 205 206 if( length ) 207 { 208 memcpy( (void *) (ctx->buffer + left), (void *) input, length ); 209 } 210 } 211 212 static uint8 md5_padding[64] = 213 { 214 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 215 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 216 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 217 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 218 }; 219 220 void md5_finish( struct md5_context *ctx, uint8 digest[16] ) 221 { 222 uint32 last, padn; 223 uint8 msglen[8]; 224 225 PUT_UINT32( ctx->total[0], msglen, 0 ); 226 PUT_UINT32( ctx->total[1], msglen, 4 ); 227 228 last = ( ctx->total[0] >> 3 ) & 0x3F; 229 padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last ); 230 231 md5_update( ctx, md5_padding, padn ); 232 md5_update( ctx, msglen, 8 ); 233 234 PUT_UINT32( ctx->state[0], digest, 0 ); 235 PUT_UINT32( ctx->state[1], digest, 4 ); 236 PUT_UINT32( ctx->state[2], digest, 8 ); 237 PUT_UINT32( ctx->state[3], digest, 12 ); 238 } -
src/lib/md5.h
diff -X /usr/src/dontdiff -urN nALFS/src/lib/md5.h nALFS-new/src/lib/md5.h
old new 1 /* 2 * md5.h - MD5 (RFC 1321) sum computation. 3 * 4 * Copyright (C) 2001-2003 5 * 6 * Christophe Devine <devine@cr0.net> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 */ 22 23 #ifndef _MD5_H 24 #define _MD5_H 25 26 #define uint8 unsigned char 27 #define uint32 unsigned long int 28 29 struct md5_context 30 { 31 uint32 total[2]; 32 uint32 state[4]; 33 uint8 buffer[64]; 34 }; 35 36 extern void md5_starts( struct md5_context *ctx ); 37 extern void md5_update( struct md5_context *ctx, uint8 *input, uint32 length ); 38 extern void md5_finish( struct md5_context *ctx, uint8 digest[16] ); 39 40 #endif /* _MD5_H */