Browse files

Added SHA384 and SHA512 digests. Tweaks for getting rid of windows wa…

…rnings. Use recv instead of read on socket. Bumped version to 0.63 (libfko) and 0.23 (FKO perl module).

git-svn-id: file:///home/mbr/svn/fwknop/trunk@123 510a4753-2344-4c79-9c09-4d669213fbeb
  • Loading branch information...
1 parent 3029e01 commit 7f45031cef416e0d0edbea58c7ce051714768ca6 Damien Stuart committed Aug 2, 2009
Showing with 357 additions and 499 deletions.
  1. +41 −32 ChangeLog
  2. +9 −3 configure.ac
  3. +2 −0 doc/libfko.texi
  4. +1 −1 fko/Makefile.am
  5. +103 −32 fko/digest.c
  6. +25 −11 fko/digest.h
  7. +2 −0 fko/fko.h
  8. +5 −2 fko/fko_common.h
  9. +19 −3 fko/fko_decode.c
  10. +21 −3 fko/fko_digest.c
  11. +1 −1 fko/md5.h
  12. +87 −87 fko/sha1.c
  13. +14 −22 fko/{sha.h → sha1.h}
  14. +0 −295 fko/sha256.c
  15. +9 −1 perl/FKO/lib/FKO.pm
  16. +4 −0 perl/FKO/lib/FKO_Constants.pl
  17. +11 −3 src/config_init.c
  18. +3 −3 src/fwknop.c
View
73 ChangeLog
@@ -1,48 +1,57 @@
+2009-08-02 Damien Stuart <dstuart@dstuart.org>
+ * Tweaks to digest code - added SHA384 and SHA512 to supported digests.
+ * Updated autoconf files to account or new headers and types recently added.
+ * Bumped libfko version to 0.63 and perl FKO module version to 0.23.
+
2009-07-26 Michael Rash <mbr@cipherdyne.org>
- * Implemented -s command line argument on the fwknop client command line
- so that the IP "0.0.0.0" can be sent within an SPA packet. The fwknopd
- server can wrap access requirements around this IP.
- * Initial public release of fwknop-c-0.62.
+ * Implemented -s command line argument on the fwknop client command line
+ so that the IP "0.0.0.0" can be sent within an SPA packet. The fwknopd
+ server can wrap access requirements around this IP.
+ * Initial public release of fwknop-c-0.62.
2009-07-23 Michael Rash <mbr@cipherdyne.org>
- * Added the --show-last and --no-save command line options to show the
- command line used for the previous fwknop invocation, and to have the
- fwknop client not save its command line arguments.
- * Bug fix to force libfko to recalculate the random data embedded in the
- the SPA packet after a random port is acquired via --rand-port or
- --nat-rand-port. This is a precaution so that an attacker cannot guess
- some of the internal SPA data based on the destination port number.
+ * Added the --show-last and --no-save command line options to show the
+ command line used for the previous fwknop invocation, and to have the
+ fwknop client not save its command line arguments.
+ * Bug fix to force libfko to recalculate the random data embedded in the
+ the SPA packet after a random port is acquired via --rand-port or
+ --nat-rand-port. This is a precaution so that an attacker cannot guess
+ some of the internal SPA data based on the destination port number.
2009-07-21 Michael Rash <mbr@cipherdyne.org>
- * Got forward and local NAT modes working with the --nat-access,
- --nat-local, --nat-port, and --nat-randport options. All NAT modes
- are now passing the fwknop test suite.
- * Added the --server-command option to build an SPA packet with a command
- for the server to execute.
- * Added the --fw-timeout option for client side timeouts to be specified.
- * Added the --time-offset-plus and --time-offset-minus options to allow
- the user to influence the timestamp associated with an SPA packet.
- * Added the --rand-port option so that the SPA packet destination port can
- be randomized.
+ * Got forward and local NAT modes working with the --nat-access,
+ --nat-local, --nat-port, and --nat-randport options. All NAT modes
+ are now passing the fwknop test suite.
+ * Added the --server-command option to build an SPA packet with a command
+ for the server to execute.
+ * Added the --fw-timeout option for client side timeouts to be specified.
+ * Added the --time-offset-plus and --time-offset-minus options to allow
+ the user to influence the timestamp associated with an SPA packet.
+ * Added the --rand-port option so that the SPA packet destination port can
+ be randomized.
2009-07-16 Michael Rash <mbr@cipherdyne.org>
- * Added the ability to send SPA packets over valid HTTP requests with
- the fwknop-c client.
- * Added support for transmitting SPA packets over IPv6 via TCP and UDP
- sockets, and also via HTTP.
- * Added GnuPG 'hQ' base64 encoded prefix handling (this prefix is
- stripped out of encrypted SPA packet data).
- * Added hostname resolution support to the fwknop-c client if the SPA
- server is specified as a hostname instead of an IP address.
+ * Added the ability to send SPA packets over valid HTTP requests with
+ the fwknop-c client.
+ * Added support for transmitting SPA packets over IPv6 via TCP and UDP
+ sockets, and also via HTTP.
+ * Added GnuPG 'hQ' base64 encoded prefix handling (this prefix is
+ stripped out of encrypted SPA packet data).
+ * Added hostname resolution support to the fwknop-c client if the SPA
+ server is specified as a hostname instead of an IP address.
+
+2008-05-24 Damien Stuart <dstuart@dstuart.org>
+ * Added win32 direcory with Visual Studio 2008 solution and project files
+ for buildin on the Windows platform.
2008-12-21 Damien Stuart <dstuart@dstuart.org>
Build 0.0.0 alpha
- * autogen.sh: created.
- * autoconf/automake: Initial configuration created.
+ * autogen.sh: created.
+ * autoconf/automake: Initial configuration created.
- Copyright 2001, 2002, 2003, 2004, 2005 g10 Code GmbH
+ Copyright 2009, Damien Stuart
This file is free software; as a special exception the author gives
unlimited permission to copy and/or distribute it, with or without
View
12 configure.ac
@@ -3,7 +3,7 @@ dnl Process thie file with autoconf to produce the configure script
AC_PREREQ(2.61)
m4_define(my_package, [fwknop-c])
-m4_define(my_version, [0.62])
+m4_define(my_version, [0.63])
m4_define(my_bug_email, [dstuart@dstuart.org])
AC_INIT(my_package, my_version, my_bug_email)
@@ -21,6 +21,7 @@ AC_GNU_SOURCE
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CXX
+AC_PROG_AWK
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
@@ -31,14 +32,18 @@ AC_PROG_LIBTOOL
# Checks for header files.
#
AC_HEADER_STDC
-AC_CHECK_HEADERS([ctype.h endian.h netinet/in.h stdint.h stdlib.h string.h strings.h sys/byteorder.h sys/endian.h sys/socket.h sys/stat.h sys/time.h termios.h unistd.h])
+AC_HEADER_TIME
+
+AC_CHECK_HEADERS([ctype.h endian.h netdb.h netinet/in.h stdint.h stdlib.h string.h strings.h sys/byteorder.h sys/endian.h sys/socket.h sys/stat.h sys/time.h termios.h unistd.h])
# Type checks.
#
AC_C_CONST
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
-AC_HEADER_TIME
+AC_TYPE_UINT32_T
+AC_TYPE_UINT8_T
+
AC_CHECK_SIZEOF(unsigned int)
AC_CHECK_TYPES([uint8_t, uint32_t])
@@ -49,6 +54,7 @@ AC_C_BIGENDIAN
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_FUNC_STAT
+
AC_CHECK_FUNCS([bzero gettimeofday memmove memset socket strchr strcspn strdup strncasecmp strndup strrchr strspn])
AC_SEARCH_LIBS([socket], [socket])
View
2 doc/libfko.texi
@@ -381,6 +381,8 @@ are (in order of strength):
@item FKO_DIGEST_MD5
@item FKO_DIGEST_SHA1
@item FKO_DIGEST_SHA256 (libfko default)
+@item FKO_DIGEST_SHA384
+@item FKO_DIGEST_SHA512
@end table
@end deftypevar
View
2 fko/Makefile.am
@@ -6,7 +6,7 @@ libfko_source_files = \
fko_decode.c fko_encryption.c fko_error.c fko_funcs.c fko_message.c \
fko_nat_access.c fko_rand_value.c fko_server_auth.c fko.h fko_limits.h \
fko_timestamp.c fko_user.c fko_util.h md5.c md5.h \
- rijndael.c rijndael.h sha1.c sha256.c sha.h strlcat.c \
+ rijndael.c rijndael.h sha1.c sha1.h sha2.c sha2.h strlcat.c \
strlcpy.c fko_state.h fko_context.h gpgme_funcs.c gpgme_funcs.h
libfko_la_SOURCES = $(libfko_source_files)
View
135 fko/digest.c
@@ -27,9 +27,10 @@
/* Convert a raw digest into its hex string representation.
*/
void
-digest_to_hex(char *out, unsigned char *in, int size)
+digest_to_hex(char *out, unsigned char *in, size_t size)
{
- int i;
+ size_t i;
+
for(i=0; i<size; i++)
{
sprintf(out, "%02x", in[i]);
@@ -40,7 +41,7 @@ digest_to_hex(char *out, unsigned char *in, int size)
/* Compute MD5 hash on in and store result in out.
*/
void
-md5(unsigned char *out, unsigned char *in, int size)
+md5(unsigned char *out, unsigned char *in, size_t size)
{
MD5Context ctx;
@@ -52,99 +53,169 @@ md5(unsigned char *out, unsigned char *in, int size)
/* Compute MD5 hash on in and store the hex string result in out.
*/
void
-md5_hex(char *out, unsigned char *in, int size)
+md5_hex(char *out, unsigned char *in, size_t size)
{
- uint8_t md[MD5_DIGESTSIZE];
+ uint8_t md[MD5_DIGEST_LENGTH];
md5(md, in, size);
- digest_to_hex(out, md, MD5_DIGESTSIZE);
+ digest_to_hex(out, md, MD5_DIGEST_LENGTH);
}
/* Compute MD5 hash on in and store the base64 string result in out.
*/
void
-md5_base64(char *out, unsigned char *in, int size)
+md5_base64(char *out, unsigned char *in, size_t size)
{
- uint8_t md[MD5_DIGESTSIZE];
+ uint8_t md[MD5_DIGEST_LENGTH];
md5(md, in, size);
- b64_encode(md, out, MD5_DIGESTSIZE);
+ b64_encode(md, out, MD5_DIGEST_LENGTH);
strip_b64_eq(out);
}
/* Compute SHA1 hash on in and store result in out.
*/
void
-sha1(unsigned char *out, unsigned char *in, int size)
+sha1(unsigned char *out, unsigned char *in, size_t size)
{
- SHA_INFO sha_info;
+ SHA1_INFO sha1_info;
- sha1_init(&sha_info);
- sha1_update(&sha_info, (uint8_t*)in, size);
- sha1_final(out, &sha_info);
+ sha1_init(&sha1_info);
+ sha1_update(&sha1_info, (uint8_t*)in, size);
+ sha1_final(out, &sha1_info);
}
/* Compute SHA1 hash on in and store the hex string result in out.
*/
void
-sha1_hex(char *out, unsigned char *in, int size)
+sha1_hex(char *out, unsigned char *in, size_t size)
{
- uint8_t md[SHA1_DIGESTSIZE];
+ uint8_t md[SHA1_DIGEST_LENGTH];
sha1(md, in, size);
- digest_to_hex(out, md, SHA1_DIGESTSIZE);
+ digest_to_hex(out, md, SHA1_DIGEST_LENGTH);
}
/* Compute SHA1 hash on in and store the base64 string result in out.
*/
void
-sha1_base64(char *out, unsigned char *in, int size)
+sha1_base64(char *out, unsigned char *in, size_t size)
{
- uint8_t md[SHA1_DIGESTSIZE];
+ uint8_t md[SHA1_DIGEST_LENGTH];
sha1(md, in, size);
- b64_encode(md, out, SHA1_DIGESTSIZE);
+ b64_encode(md, out, SHA1_DIGEST_LENGTH);
strip_b64_eq(out);
}
/* Compute SHA256 hash on in and store the hex string result in out.
*/
void
-sha256(unsigned char *out, unsigned char *in, int size)
+sha256(unsigned char *out, unsigned char *in, size_t size)
{
- SHA_INFO sha_info;
+ SHA256_CTX sha256_ctx;
- sha256_init(&sha_info);
- sha256_update(&sha_info, (uint8_t*)in, size);
- sha256_final(&sha_info);
- sha256_unpackdigest(out, &sha_info);
+ SHA256_Init(&sha256_ctx);
+ SHA256_Update(&sha256_ctx, (const uint8_t*)in, size);
+ SHA256_Final(out, &sha256_ctx);
}
/* Compute SHA256 hash on in and store the hex string result in out.
*/
void
-sha256_hex(char *out, unsigned char *in, int size)
+sha256_hex(char *out, unsigned char *in, size_t size)
{
- uint8_t md[SHA256_DIGESTSIZE];
+ uint8_t md[SHA256_DIGEST_LENGTH];
sha256(md, in, size);
- digest_to_hex(out, md, SHA256_DIGESTSIZE);
+ digest_to_hex(out, md, SHA256_DIGEST_LENGTH);
}
/* Compute SHA256 hash on in and store the base64 string result in out.
*/
void
-sha256_base64(char *out, unsigned char *in, int size)
+sha256_base64(char *out, unsigned char *in, size_t size)
{
- uint8_t md[SHA256_DIGESTSIZE];
+ uint8_t md[SHA256_DIGEST_LENGTH];
sha256(md, in, size);
- b64_encode(md, out, SHA256_DIGESTSIZE);
+ b64_encode(md, out, SHA256_DIGEST_LENGTH);
+
+ strip_b64_eq(out);
+}
+
+/* Compute SHA384 hash on in and store the hex string result in out.
+*/
+void
+sha384(unsigned char *out, unsigned char *in, size_t size)
+{
+ SHA384_CTX sha384_ctx;
+
+ SHA384_Init(&sha384_ctx);
+ SHA384_Update(&sha384_ctx, (const uint8_t*)in, size);
+ SHA384_Final(out, &sha384_ctx);
+}
+
+/* Compute SHA384 hash on in and store the hex string result in out.
+*/
+void
+sha384_hex(char *out, unsigned char *in, size_t size)
+{
+ uint8_t md[SHA384_DIGEST_LENGTH];
+
+ sha384(md, in, size);
+ digest_to_hex(out, md, SHA384_DIGEST_LENGTH);
+}
+
+/* Compute SHA384 hash on in and store the base64 string result in out.
+*/
+void
+sha384_base64(char *out, unsigned char *in, size_t size)
+{
+ uint8_t md[SHA384_DIGEST_LENGTH];
+
+ sha384(md, in, size);
+ b64_encode(md, out, SHA384_DIGEST_LENGTH);
strip_b64_eq(out);
}
+/* Compute SHA512 hash on in and store the hex string result in out.
+*/
+void
+sha512(unsigned char *out, unsigned char *in, size_t size)
+{
+ SHA512_CTX sha512_ctx;
+
+ SHA512_Init(&sha512_ctx);
+ SHA512_Update(&sha512_ctx, (const uint8_t*)in, size);
+ SHA512_Final(out, &sha512_ctx);
+}
+
+/* Compute SHA512 hash on in and store the hex string result in out.
+*/
+void
+sha512_hex(char *out, unsigned char *in, size_t size)
+{
+ uint8_t md[SHA512_DIGEST_LENGTH];
+
+ sha512(md, in, size);
+ digest_to_hex(out, md, SHA512_DIGEST_LENGTH);
+}
+
+/* Compute SHA512 hash on in and store the base64 string result in out.
+*/
+void
+sha512_base64(char *out, unsigned char *in, size_t size)
+{
+ uint8_t md[SHA512_DIGEST_LENGTH];
+
+ sha512(md, in, size);
+ b64_encode(md, out, SHA512_DIGEST_LENGTH);
+
+ strip_b64_eq(out);
+}
/***EOF***/
View
36 fko/digest.h
@@ -27,22 +27,36 @@
#include "fko_common.h"
#include "md5.h"
-#include "sha.h"
+#include "sha1.h"
+#include "sha2.h"
/* Size calculation macros
*/
#define MD_HEX_SIZE(x) x * 2
-#define MD_B64_SIZE(x) ((x * 4) / 3) + 1
-void md5(unsigned char* out, unsigned char* in, int size);
-void md5_hex(char* out, unsigned char* in, int size);
-void md5_base64(char* out, unsigned char* in, int size);
-void sha1(unsigned char* out, unsigned char* in, int size);
-void sha1_hex(char* out, unsigned char* in, int size);
-void sha1_base64(char* out, unsigned char* in, int size);
-void sha256(unsigned char* out, unsigned char* in, int size);
-void sha256_hex(char* out, unsigned char* in, int size);
-void sha256_base64(char* out, unsigned char* in, int size);
+/* Predefined base64 encoded digest sizes.
+*/
+#define MD5_B64_LENGTH 22
+#define SHA1_B64_LENGTH 27
+#define SHA256_B64_LENGTH 43
+#define SHA384_B64_LENGTH 64
+#define SHA512_B64_LENGTH 86
+
+void md5(unsigned char* out, unsigned char* in, size_t size);
+void md5_hex(char* out, unsigned char* in, size_t size);
+void md5_base64(char* out, unsigned char* in, size_t size);
+void sha1(unsigned char* out, unsigned char* in, size_t size);
+void sha1_hex(char* out, unsigned char* in, size_t size);
+void sha1_base64(char* out, unsigned char* in, size_t size);
+void sha256(unsigned char* out, unsigned char* in, size_t size);
+void sha256_hex(char* out, unsigned char* in, size_t size);
+void sha256_base64(char* out, unsigned char* in, size_t size);
+void sha384(unsigned char* out, unsigned char* in, size_t size);
+void sha384_hex(char* out, unsigned char* in, size_t size);
+void sha384_base64(char* out, unsigned char* in, size_t size);
+void sha512(unsigned char* out, unsigned char* in, size_t size);
+void sha512_hex(char* out, unsigned char* in, size_t size);
+void sha512_base64(char* out, unsigned char* in, size_t size);
#endif /* DIGEST_H */
View
2 fko/fko.h
@@ -67,6 +67,8 @@ typedef enum {
FKO_DIGEST_MD5 = 1,
FKO_DIGEST_SHA1,
FKO_DIGEST_SHA256,
+ FKO_DIGEST_SHA384,
+ FKO_DIGEST_SHA512,
FKO_LAST_DIGEST_TYPE /* Always leave this as the last one */
} fko_digest_type_t;
View
7 fko/fko_common.h
@@ -52,8 +52,11 @@
#endif
#ifdef WIN32
- typedef unsigned char uint8_t;
- typedef unsigned int uint32_t;
+ /* These are needed for the digest code under windows.
+ */
+ typedef unsigned __int8 uint8_t;
+ typedef unsigned __int32 uint32_t;
+ typedef unsigned __int64 uint64_t;
#define strdup _strdup
#else
View
22 fko/fko_decode.c
@@ -57,18 +57,26 @@ fko_decode_spa_data(fko_ctx_t ctx)
switch(t_size)
{
- case MD_B64_SIZE(MD5_DIGESTSIZE):
+ case MD5_B64_LENGTH:
ctx->digest_type = FKO_DIGEST_MD5;
break;
- case MD_B64_SIZE(SHA1_DIGESTSIZE):
+ case SHA1_B64_LENGTH:
ctx->digest_type = FKO_DIGEST_SHA1;
break;
- case MD_B64_SIZE(SHA256_DIGESTSIZE):
+ case SHA256_B64_LENGTH:
ctx->digest_type = FKO_DIGEST_SHA256;
break;
+ case SHA384_B64_LENGTH:
+ ctx->digest_type = FKO_DIGEST_SHA384;
+ break;
+
+ case SHA512_B64_LENGTH:
+ ctx->digest_type = FKO_DIGEST_SHA512;
+ break;
+
default: /* Invalid or unsupported digest */
return(FKO_ERROR_INVALID_DIGEST_TYPE);
}
@@ -108,6 +116,14 @@ fko_decode_spa_data(fko_ctx_t ctx)
sha256_base64(tbuf, (unsigned char*)ctx->encoded_msg, strlen(ctx->encoded_msg));
break;
+ case FKO_DIGEST_SHA384:
+ sha384_base64(tbuf, (unsigned char*)ctx->encoded_msg, strlen(ctx->encoded_msg));
+ break;
+
+ case FKO_DIGEST_SHA512:
+ sha512_base64(tbuf, (unsigned char*)ctx->encoded_msg, strlen(ctx->encoded_msg));
+ break;
+
}
/* We give up here if the computed digest does not match the
View
24 fko/fko_digest.c
@@ -82,7 +82,7 @@ fko_set_spa_digest(fko_ctx_t ctx)
switch(ctx->digest_type)
{
case FKO_DIGEST_MD5:
- md = malloc(MD_HEX_SIZE(MD5_DIGESTSIZE)+1);
+ md = malloc(MD_HEX_SIZE(MD5_DIGEST_LENGTH)+1);
if(md == NULL)
return(FKO_ERROR_MEMORY_ALLOCATION);
@@ -91,7 +91,7 @@ fko_set_spa_digest(fko_ctx_t ctx)
break;
case FKO_DIGEST_SHA1:
- md = malloc(MD_HEX_SIZE(SHA1_DIGESTSIZE)+1);
+ md = malloc(MD_HEX_SIZE(SHA1_DIGEST_LENGTH)+1);
if(md == NULL)
return(FKO_ERROR_MEMORY_ALLOCATION);
@@ -100,14 +100,32 @@ fko_set_spa_digest(fko_ctx_t ctx)
break;
case FKO_DIGEST_SHA256:
- md = malloc(MD_HEX_SIZE(SHA256_DIGESTSIZE)+1);
+ md = malloc(MD_HEX_SIZE(SHA256_DIGEST_LENGTH)+1);
if(md == NULL)
return(FKO_ERROR_MEMORY_ALLOCATION);
sha256_base64(md,
(unsigned char*)ctx->encoded_msg, strlen(ctx->encoded_msg));
break;
+ case FKO_DIGEST_SHA384:
+ md = malloc(MD_HEX_SIZE(SHA384_DIGEST_LENGTH)+1);
+ if(md == NULL)
+ return(FKO_ERROR_MEMORY_ALLOCATION);
+
+ sha384_base64(md,
+ (unsigned char*)ctx->encoded_msg, strlen(ctx->encoded_msg));
+ break;
+
+ case FKO_DIGEST_SHA512:
+ md = malloc(MD_HEX_SIZE(SHA512_DIGEST_LENGTH)+1);
+ if(md == NULL)
+ return(FKO_ERROR_MEMORY_ALLOCATION);
+
+ sha512_base64(md,
+ (unsigned char*)ctx->encoded_msg, strlen(ctx->encoded_msg));
+ break;
+
default:
return(FKO_ERROR_INVALID_DIGEST_TYPE);
}
View
2 fko/md5.h
@@ -32,7 +32,7 @@
#include "fko_common.h"
-#define MD5_DIGESTSIZE 16
+#define MD5_DIGEST_LENGTH 16
typedef struct _MD5Context {
uint32_t buf[4];
View
174 fko/sha1.c
@@ -16,7 +16,7 @@
*
*****************************************************************************
*/
-#include "sha.h"
+#include "sha1.h"
/* SHA f()-functions */
#define f1(x,y,z) ((x & y) | (~x & z))
@@ -62,13 +62,13 @@
void
-sha1_transform(SHA_INFO *sha_info)
+sha1_transform(SHA1_INFO *sha1_info)
{
int i;
uint8_t *dp;
uint32_t T, A, B, C, D, E, W[80], *WP;
- dp = sha_info->data;
+ dp = sha1_info->data;
#undef SWAP_DONE
@@ -132,11 +132,11 @@ sha1_transform(SHA_INFO *sha_info)
W[i] = W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16];
W[i] = R32(W[i], 1);
}
- A = sha_info->digest[0];
- B = sha_info->digest[1];
- C = sha_info->digest[2];
- D = sha_info->digest[3];
- E = sha_info->digest[4];
+ A = sha1_info->digest[0];
+ B = sha1_info->digest[1];
+ C = sha1_info->digest[2];
+ D = sha1_info->digest[3];
+ E = sha1_info->digest[4];
WP = W;
#ifdef UNRAVEL
FA(1); FB(1); FC(1); FD(1); FE(1); FT(1); FA(1); FB(1); FC(1); FD(1);
@@ -147,11 +147,11 @@ sha1_transform(SHA_INFO *sha_info)
FC(3); FD(3); FE(3); FT(3); FA(3); FB(3); FC(3); FD(3); FE(3); FT(3);
FA(4); FB(4); FC(4); FD(4); FE(4); FT(4); FA(4); FB(4); FC(4); FD(4);
FE(4); FT(4); FA(4); FB(4); FC(4); FD(4); FE(4); FT(4); FA(4); FB(4);
- sha_info->digest[0] = T32(sha_info->digest[0] + E);
- sha_info->digest[1] = T32(sha_info->digest[1] + T);
- sha_info->digest[2] = T32(sha_info->digest[2] + A);
- sha_info->digest[3] = T32(sha_info->digest[3] + B);
- sha_info->digest[4] = T32(sha_info->digest[4] + C);
+ sha1_info->digest[0] = T32(sha1_info->digest[0] + E);
+ sha1_info->digest[1] = T32(sha1_info->digest[1] + T);
+ sha1_info->digest[2] = T32(sha1_info->digest[2] + A);
+ sha1_info->digest[3] = T32(sha1_info->digest[3] + B);
+ sha1_info->digest[4] = T32(sha1_info->digest[4] + C);
#else /* !UNRAVEL */
#ifdef UNROLL_LOOPS
FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1);
@@ -168,123 +168,123 @@ sha1_transform(SHA_INFO *sha_info)
for (i = 40; i < 60; ++i) { FG(3); }
for (i = 60; i < 80; ++i) { FG(4); }
#endif /* !UNROLL_LOOPS */
- sha_info->digest[0] = T32(sha_info->digest[0] + A);
- sha_info->digest[1] = T32(sha_info->digest[1] + B);
- sha_info->digest[2] = T32(sha_info->digest[2] + C);
- sha_info->digest[3] = T32(sha_info->digest[3] + D);
- sha_info->digest[4] = T32(sha_info->digest[4] + E);
+ sha1_info->digest[0] = T32(sha1_info->digest[0] + A);
+ sha1_info->digest[1] = T32(sha1_info->digest[1] + B);
+ sha1_info->digest[2] = T32(sha1_info->digest[2] + C);
+ sha1_info->digest[3] = T32(sha1_info->digest[3] + D);
+ sha1_info->digest[4] = T32(sha1_info->digest[4] + E);
#endif /* !UNRAVEL */
}
/* initialize the SHA digest */
void
-sha1_init(SHA_INFO *sha_info)
+sha1_init(SHA1_INFO *sha1_info)
{
- sha_info->digest[0] = 0x67452301L;
- sha_info->digest[1] = 0xefcdab89L;
- sha_info->digest[2] = 0x98badcfeL;
- sha_info->digest[3] = 0x10325476L;
- sha_info->digest[4] = 0xc3d2e1f0L;
- sha_info->count_lo = 0L;
- sha_info->count_hi = 0L;
- sha_info->local = 0;
+ sha1_info->digest[0] = 0x67452301L;
+ sha1_info->digest[1] = 0xefcdab89L;
+ sha1_info->digest[2] = 0x98badcfeL;
+ sha1_info->digest[3] = 0x10325476L;
+ sha1_info->digest[4] = 0xc3d2e1f0L;
+ sha1_info->count_lo = 0L;
+ sha1_info->count_hi = 0L;
+ sha1_info->local = 0;
}
/* update the SHA digest */
void
-sha1_update(SHA_INFO *sha_info, uint8_t *buffer, int count)
+sha1_update(SHA1_INFO *sha1_info, uint8_t *buffer, int count)
{
int i;
uint32_t clo;
- clo = T32(sha_info->count_lo + ((uint32_t) count << 3));
- if (clo < sha_info->count_lo) {
- ++sha_info->count_hi;
+ clo = T32(sha1_info->count_lo + ((uint32_t) count << 3));
+ if (clo < sha1_info->count_lo) {
+ ++sha1_info->count_hi;
}
- sha_info->count_lo = clo;
- sha_info->count_hi += (uint32_t) count >> 29;
- if (sha_info->local) {
- i = SHA_BLOCKSIZE - sha_info->local;
+ sha1_info->count_lo = clo;
+ sha1_info->count_hi += (uint32_t) count >> 29;
+ if (sha1_info->local) {
+ i = SHA1_BLOCKSIZE - sha1_info->local;
if (i > count) {
i = count;
}
- memcpy(((uint8_t *) sha_info->data) + sha_info->local, buffer, i);
+ memcpy(((uint8_t *) sha1_info->data) + sha1_info->local, buffer, i);
count -= i;
buffer += i;
- sha_info->local += i;
- if (sha_info->local == SHA_BLOCKSIZE) {
- sha1_transform(sha_info);
+ sha1_info->local += i;
+ if (sha1_info->local == SHA1_BLOCKSIZE) {
+ sha1_transform(sha1_info);
} else {
return;
}
}
- while (count >= SHA_BLOCKSIZE) {
- memcpy(sha_info->data, buffer, SHA_BLOCKSIZE);
- buffer += SHA_BLOCKSIZE;
- count -= SHA_BLOCKSIZE;
- sha1_transform(sha_info);
+ while (count >= SHA1_BLOCKSIZE) {
+ memcpy(sha1_info->data, buffer, SHA1_BLOCKSIZE);
+ buffer += SHA1_BLOCKSIZE;
+ count -= SHA1_BLOCKSIZE;
+ sha1_transform(sha1_info);
}
- memcpy(sha_info->data, buffer, count);
- sha_info->local = count;
+ memcpy(sha1_info->data, buffer, count);
+ sha1_info->local = count;
}
void
-sha1_transform_and_copy(unsigned char digest[20], SHA_INFO *sha_info)
+sha1_transform_and_copy(unsigned char digest[20], SHA1_INFO *sha1_info)
{
- sha1_transform(sha_info);
- digest[ 0] = (unsigned char) ((sha_info->digest[0] >> 24) & 0xff);
- digest[ 1] = (unsigned char) ((sha_info->digest[0] >> 16) & 0xff);
- digest[ 2] = (unsigned char) ((sha_info->digest[0] >> 8) & 0xff);
- digest[ 3] = (unsigned char) ((sha_info->digest[0] ) & 0xff);
- digest[ 4] = (unsigned char) ((sha_info->digest[1] >> 24) & 0xff);
- digest[ 5] = (unsigned char) ((sha_info->digest[1] >> 16) & 0xff);
- digest[ 6] = (unsigned char) ((sha_info->digest[1] >> 8) & 0xff);
- digest[ 7] = (unsigned char) ((sha_info->digest[1] ) & 0xff);
- digest[ 8] = (unsigned char) ((sha_info->digest[2] >> 24) & 0xff);
- digest[ 9] = (unsigned char) ((sha_info->digest[2] >> 16) & 0xff);
- digest[10] = (unsigned char) ((sha_info->digest[2] >> 8) & 0xff);
- digest[11] = (unsigned char) ((sha_info->digest[2] ) & 0xff);
- digest[12] = (unsigned char) ((sha_info->digest[3] >> 24) & 0xff);
- digest[13] = (unsigned char) ((sha_info->digest[3] >> 16) & 0xff);
- digest[14] = (unsigned char) ((sha_info->digest[3] >> 8) & 0xff);
- digest[15] = (unsigned char) ((sha_info->digest[3] ) & 0xff);
- digest[16] = (unsigned char) ((sha_info->digest[4] >> 24) & 0xff);
- digest[17] = (unsigned char) ((sha_info->digest[4] >> 16) & 0xff);
- digest[18] = (unsigned char) ((sha_info->digest[4] >> 8) & 0xff);
- digest[19] = (unsigned char) ((sha_info->digest[4] ) & 0xff);
+ sha1_transform(sha1_info);
+ digest[ 0] = (unsigned char) ((sha1_info->digest[0] >> 24) & 0xff);
+ digest[ 1] = (unsigned char) ((sha1_info->digest[0] >> 16) & 0xff);
+ digest[ 2] = (unsigned char) ((sha1_info->digest[0] >> 8) & 0xff);
+ digest[ 3] = (unsigned char) ((sha1_info->digest[0] ) & 0xff);
+ digest[ 4] = (unsigned char) ((sha1_info->digest[1] >> 24) & 0xff);
+ digest[ 5] = (unsigned char) ((sha1_info->digest[1] >> 16) & 0xff);
+ digest[ 6] = (unsigned char) ((sha1_info->digest[1] >> 8) & 0xff);
+ digest[ 7] = (unsigned char) ((sha1_info->digest[1] ) & 0xff);
+ digest[ 8] = (unsigned char) ((sha1_info->digest[2] >> 24) & 0xff);
+ digest[ 9] = (unsigned char) ((sha1_info->digest[2] >> 16) & 0xff);
+ digest[10] = (unsigned char) ((sha1_info->digest[2] >> 8) & 0xff);
+ digest[11] = (unsigned char) ((sha1_info->digest[2] ) & 0xff);
+ digest[12] = (unsigned char) ((sha1_info->digest[3] >> 24) & 0xff);
+ digest[13] = (unsigned char) ((sha1_info->digest[3] >> 16) & 0xff);
+ digest[14] = (unsigned char) ((sha1_info->digest[3] >> 8) & 0xff);
+ digest[15] = (unsigned char) ((sha1_info->digest[3] ) & 0xff);
+ digest[16] = (unsigned char) ((sha1_info->digest[4] >> 24) & 0xff);
+ digest[17] = (unsigned char) ((sha1_info->digest[4] >> 16) & 0xff);
+ digest[18] = (unsigned char) ((sha1_info->digest[4] >> 8) & 0xff);
+ digest[19] = (unsigned char) ((sha1_info->digest[4] ) & 0xff);
}
/* finish computing the SHA digest */
void
-sha1_final(uint8_t digest[20], SHA_INFO *sha_info)
+sha1_final(uint8_t digest[20], SHA1_INFO *sha1_info)
{
int count;
uint32_t lo_bit_count, hi_bit_count;
- lo_bit_count = sha_info->count_lo;
- hi_bit_count = sha_info->count_hi;
+ lo_bit_count = sha1_info->count_lo;
+ hi_bit_count = sha1_info->count_hi;
count = (int) ((lo_bit_count >> 3) & 0x3f);
- ((uint8_t *) sha_info->data)[count++] = 0x80;
- if (count > SHA_BLOCKSIZE - 8) {
- memset(((uint8_t *) sha_info->data) + count, 0, SHA_BLOCKSIZE - count);
- sha1_transform(sha_info);
- memset((uint8_t *) sha_info->data, 0, SHA_BLOCKSIZE - 8);
+ ((uint8_t *) sha1_info->data)[count++] = 0x80;
+ if (count > SHA1_BLOCKSIZE - 8) {
+ memset(((uint8_t *) sha1_info->data) + count, 0, SHA1_BLOCKSIZE - count);
+ sha1_transform(sha1_info);
+ memset((uint8_t *) sha1_info->data, 0, SHA1_BLOCKSIZE - 8);
} else {
- memset(((uint8_t *) sha_info->data) + count, 0,
- SHA_BLOCKSIZE - 8 - count);
+ memset(((uint8_t *) sha1_info->data) + count, 0,
+ SHA1_BLOCKSIZE - 8 - count);
}
- sha_info->data[56] = (uint8_t)((hi_bit_count >> 24) & 0xff);
- sha_info->data[57] = (uint8_t)((hi_bit_count >> 16) & 0xff);
- sha_info->data[58] = (uint8_t)((hi_bit_count >> 8) & 0xff);
- sha_info->data[59] = (uint8_t)((hi_bit_count >> 0) & 0xff);
- sha_info->data[60] = (uint8_t)((lo_bit_count >> 24) & 0xff);
- sha_info->data[61] = (uint8_t)((lo_bit_count >> 16) & 0xff);
- sha_info->data[62] = (uint8_t)((lo_bit_count >> 8) & 0xff);
- sha_info->data[63] = (uint8_t)((lo_bit_count >> 0) & 0xff);
- sha1_transform_and_copy(digest, sha_info);
+ sha1_info->data[56] = (uint8_t)((hi_bit_count >> 24) & 0xff);
+ sha1_info->data[57] = (uint8_t)((hi_bit_count >> 16) & 0xff);
+ sha1_info->data[58] = (uint8_t)((hi_bit_count >> 8) & 0xff);
+ sha1_info->data[59] = (uint8_t)((hi_bit_count >> 0) & 0xff);
+ sha1_info->data[60] = (uint8_t)((lo_bit_count >> 24) & 0xff);
+ sha1_info->data[61] = (uint8_t)((lo_bit_count >> 16) & 0xff);
+ sha1_info->data[62] = (uint8_t)((lo_bit_count >> 8) & 0xff);
+ sha1_info->data[63] = (uint8_t)((lo_bit_count >> 0) & 0xff);
+ sha1_transform_and_copy(digest, sha1_info);
}
/***EOF***/
View
36 fko/sha.h → fko/sha1.h
@@ -1,12 +1,12 @@
/* $Id$
*****************************************************************************
*
- * File: sha.h
+ * File: sha1.h
*
- * Purpose: Header for sha.c
+ * Purpose: Header for sha1.c
*
- * sha - An implementation of the NIST SHA Message Digest
- * algorithm. This header covers SHA1 and SHA256
+ * sha - An implementation of the NIST SHA1 Message Digest
+ * algorithm.
*
* Copyright (C) 2001 Rafael R. Sevilla <sevillar@team.ph.inter.net>
* This library is free software; you can redistribute it and/or
@@ -25,8 +25,8 @@
*
*****************************************************************************
*/
-#ifndef SHA_H
-#define SHA_H 1
+#ifndef SHA1_H
+#define SHA1_H 1
#include "fko_common.h"
@@ -40,28 +40,20 @@
#define TRUNC32(x) ((x) & 0xffffffffL)
#endif
-#define SHA_BLOCKSIZE 64
-#define SHA1_DIGESTSIZE 20
-#define SHA256_DIGESTSIZE 32
+#define SHA1_BLOCKSIZE 64
+#define SHA1_DIGEST_LENGTH 20
typedef struct {
uint32_t digest[8];
uint32_t count_lo, count_hi;
- uint8_t data[SHA_BLOCKSIZE];
+ uint8_t data[SHA1_BLOCKSIZE];
int local;
-} SHA_INFO;
+} SHA1_INFO;
/* SHA1 prototypes.
*/
-void sha1_init(SHA_INFO *sha_info);
-void sha1_update(SHA_INFO *sha_info, uint8_t *buffer, int count);
-void sha1_final(uint8_t digest[SHA1_DIGESTSIZE], SHA_INFO *sha_info);
+void sha1_init(SHA1_INFO *sha1_info);
+void sha1_update(SHA1_INFO *sha1_info, uint8_t *buffer, int count);
+void sha1_final(uint8_t digest[SHA1_DIGEST_LENGTH], SHA1_INFO *sha1_info);
-/* SHA256 prototypes.
-*/
-void sha256_init(SHA_INFO *sha_info);
-void sha256_update(SHA_INFO *sha_info, uint8_t *buffer, int count);
-void sha256_final(SHA_INFO *sha_info);
-void sha256_unpackdigest(uint8_t digest[SHA256_DIGESTSIZE], SHA_INFO *sha_info);
-
-#endif /* SHA_H */
+#endif /* SHA1_H */
View
295 fko/sha256.c
@@ -1,295 +0,0 @@
-/* $Id$
- *****************************************************************************
- *
- * File: sha256.c
- *
- * Purpose: Implementation of the SHA256 message-digest algorithm for
- * libfwknop.
- *
- *
- * Copyright (C) 2001 Rafael R. Sevilla <sevillar@team.ph.inter.net>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- *****************************************************************************
-*/
-#include "sha.h"
-
-/* 32-bit rotate to the RIGHT
-*/
-#define ROT32(x,n) TRUNC32(((x >> n) | (x << (32 - n))))
-
-#define CH(x, y, z) (((x) & (y))^(~(x) & (z)))
-#define MAJ(x, y, z)(((x) & (y))^((x) & (z))^((y) & (z)))
-
-/* Upper-case sigma functions in SHA spec
-*/
-#define USIG0(x) (ROT32(x, 2)^ROT32(x, 13)^ROT32(x, 22))
-#define USIG1(x) (ROT32(x, 6)^ROT32(x, 11)^ROT32(x, 25))
-
-/* Lower-case sigma functions in SHA spec
-*/
-#define LSIG0(x) (ROT32(x, 7)^ROT32(x, 18)^TRUNC32(x >> 3))
-#define LSIG1(x) (ROT32(x, 17)^ROT32(x, 19)^TRUNC32(x >> 10))
-
-/* SHA256 constants
-*/
-static uint32_t K[64] = {
- 0x428a2f98L, 0x71374491L, 0xb5c0fbcfL, 0xe9b5dba5L,
- 0x3956c25bL, 0x59f111f1L, 0x923f82a4L, 0xab1c5ed5L,
- 0xd807aa98L, 0x12835b01L, 0x243185beL, 0x550c7dc3L,
- 0x72be5d74L, 0x80deb1feL, 0x9bdc06a7L, 0xc19bf174L,
- 0xe49b69c1L, 0xefbe4786L, 0x0fc19dc6L, 0x240ca1ccL,
- 0x2de92c6fL, 0x4a7484aaL, 0x5cb0a9dcL, 0x76f988daL,
- 0x983e5152L, 0xa831c66dL, 0xb00327c8L, 0xbf597fc7L,
- 0xc6e00bf3L, 0xd5a79147L, 0x06ca6351L, 0x14292967L,
- 0x27b70a85L, 0x2e1b2138L, 0x4d2c6dfcL, 0x53380d13L,
- 0x650a7354L, 0x766a0abbL, 0x81c2c92eL, 0x92722c85L,
- 0xa2bfe8a1L, 0xa81a664bL, 0xc24b8b70L, 0xc76c51a3L,
- 0xd192e819L, 0xd6990624L, 0xf40e3585L, 0x106aa070L,
- 0x19a4c116L, 0x1e376c08L, 0x2748774cL, 0x34b0bcb5L,
- 0x391c0cb3L, 0x4ed8aa4aL, 0x5b9cca4fL, 0x682e6ff3L,
- 0x748f82eeL, 0x78a5636fL, 0x84c87814L, 0x8cc70208L,
- 0x90befffaL, 0xa4506cebL, 0xbef9a3f7L, 0xc67178f2L
-};
-
-static void
-sha256_transform(SHA_INFO *sha_info)
-{
- int i, j;
- uint8_t *dp;
- uint32_t T, T1, T2, A, B, C, D, E, F, G, H, W[64];
-
- dp = sha_info->data;
-
-#undef SWAP_DONE
-
-#if BYTEORDER == 1234
-#define SWAP_DONE
- for (i = 0; i < 16; ++i) {
- T = *((uint32_t *) dp);
- dp += 4;
- W[i] =
- ((T << 24) & 0xff000000) |
- ((T << 8) & 0x00ff0000) |
- ((T >> 8) & 0x0000ff00) | ((T >> 24) & 0x000000ff);
- }
-#endif
-
-#if BYTEORDER == 4321
-#define SWAP_DONE
- for (i = 0; i < 16; ++i) {
- T = *((uint32_t *) dp);
- dp += 4;
- W[i] = TRUNC32(T);
- }
-#endif
-
-#if BYTEORDER == 12345678
-#define SWAP_DONE
- for (i = 0; i < 16; i += 2) {
- T = *((uint32_t *) dp);
- dp += 8;
- W[i] = ((T << 24) & 0xff000000) | ((T << 8) & 0x00ff0000) |
- ((T >> 8) & 0x0000ff00) | ((T >> 24) & 0x000000ff);
- T >>= 32;
- W[i+1] = ((T << 24) & 0xff000000) | ((T << 8) & 0x00ff0000) |
- ((T >> 8) & 0x0000ff00) | ((T >> 24) & 0x000000ff);
- }
-#endif
-
-#if BYTEORDER == 87654321
-#define SWAP_DONE
- for (i = 0; i < 16; i += 2) {
- T = *((uint32_t *) dp);
- dp += 8;
- W[i] = TRUNC32(T >> 32);
- W[i+1] = TRUNC32(T);
- }
-#endif
-
-#ifndef SWAP_DONE
-#define SWAP_DONE
- for (i = 0; i < 16; ++i) {
- T = *((uint32_t *) dp);
- dp += 4;
- W[i] = TRUNC32(T);
- }
- #ifndef WIN32
- #warning Undetermined or unsupported Byte Order... We will try LITTLE_ENDIAN
- #endif
-#endif /* SWAP_DONE */
-
- A = sha_info->digest[0];
- B = sha_info->digest[1];
- C = sha_info->digest[2];
- D = sha_info->digest[3];
- E = sha_info->digest[4];
- F = sha_info->digest[5];
- G = sha_info->digest[6];
- H = sha_info->digest[7];
-
- for (i=16; i<64; i++)
- W[i] = TRUNC32(LSIG1(W[i-2]) + W[i-7] + LSIG0(W[i-15]) + W[i-16]);
-
- for (j=0; j<64; j++) {
- T1 = TRUNC32(H + USIG1(E) + CH(E, F, G) + K[j] + W[j]);
- T2 = TRUNC32(USIG0(A) + MAJ(A, B, C));
- H = G;
- G = F;
- F = E;
- E = TRUNC32(D + T1);
- D = C;
- C = B;
- B = A;
- A = TRUNC32(T1 + T2);
- }
-
- sha_info->digest[0] = TRUNC32(sha_info->digest[0] + A);
- sha_info->digest[1] = TRUNC32(sha_info->digest[1] + B);
- sha_info->digest[2] = TRUNC32(sha_info->digest[2] + C);
- sha_info->digest[3] = TRUNC32(sha_info->digest[3] + D);
- sha_info->digest[4] = TRUNC32(sha_info->digest[4] + E);
- sha_info->digest[5] = TRUNC32(sha_info->digest[5] + F);
- sha_info->digest[6] = TRUNC32(sha_info->digest[6] + G);
- sha_info->digest[7] = TRUNC32(sha_info->digest[7] + H);
-}
-
-void
-sha256_init(SHA_INFO *sha_info)
-{
- sha_info->digest[0] = 0x6a09e667L;
- sha_info->digest[1] = 0xbb67ae85L;
- sha_info->digest[2] = 0x3c6ef372L;
- sha_info->digest[3] = 0xa54ff53aL;
- sha_info->digest[4] = 0x510e527fL;
- sha_info->digest[5] = 0x9b05688cL;
- sha_info->digest[6] = 0x1f83d9abL;
- sha_info->digest[7] = 0x5be0cd19L;
- sha_info->count_lo = 0L;
- sha_info->count_hi = 0L;
- sha_info->local = 0;
- memset((uint8_t *)sha_info->data, 0, SHA_BLOCKSIZE);
-}
-
-/* Update the SHA digest
-*/
-void
-sha256_update(SHA_INFO *sha_info, uint8_t *buffer, int count)
-{
- int i;
- uint32_t clo;
-
- clo = TRUNC32(sha_info->count_lo + ((uint8_t) count << 3));
- if (clo < sha_info->count_lo) {
- sha_info->count_hi++;
- }
- sha_info->count_lo = clo;
- sha_info->count_hi += (uint32_t) count >> 29;
- if (sha_info->local) {
- i = SHA_BLOCKSIZE - sha_info->local;
- if (i > count) {
- i = count;
- }
- memcpy(((uint8_t *) sha_info->data) + sha_info->local, buffer, i);
- count -= i;
- buffer += i;
- sha_info->local += i;
- if (sha_info->local == SHA_BLOCKSIZE) {
- sha256_transform(sha_info);
- } else {
- return;
- }
- }
- while (count >= SHA_BLOCKSIZE) {
- memcpy(sha_info->data, buffer, SHA_BLOCKSIZE);
- buffer += SHA_BLOCKSIZE;
- count -= SHA_BLOCKSIZE;
- sha256_transform(sha_info);
- }
- memcpy(sha_info->data, buffer, count);
- sha_info->local = count;
-}
-
-/* Finish computing the SHA digest
-*/
-void
-sha256_final(SHA_INFO *sha_info)
-{
- int count;
- uint32_t lo_bit_count, hi_bit_count;
-
- lo_bit_count = sha_info->count_lo;
- hi_bit_count = sha_info->count_hi;
- count = (int) ((lo_bit_count >> 3) & 0x3f);
- ((uint8_t *) sha_info->data)[count++] = 0x80;
- if (count > SHA_BLOCKSIZE - 8) {
- memset(((uint8_t *) sha_info->data) + count, 0, SHA_BLOCKSIZE - count);
- sha256_transform(sha_info);
- memset((uint8_t *) sha_info->data, 0, SHA_BLOCKSIZE - 8);
- } else {
- memset(((uint8_t *) sha_info->data) + count, 0,
- SHA_BLOCKSIZE - 8 - count);
- }
- sha_info->data[56] = (hi_bit_count >> 24) & 0xff;
- sha_info->data[57] = (hi_bit_count >> 16) & 0xff;
- sha_info->data[58] = (hi_bit_count >> 8) & 0xff;
- sha_info->data[59] = (hi_bit_count >> 0) & 0xff;
- sha_info->data[60] = (lo_bit_count >> 24) & 0xff;
- sha_info->data[61] = (lo_bit_count >> 16) & 0xff;
- sha_info->data[62] = (lo_bit_count >> 8) & 0xff;
- sha_info->data[63] = (lo_bit_count >> 0) & 0xff;
- sha256_transform(sha_info);
-}
-
-void
-sha256_unpackdigest(uint8_t digest[32], SHA_INFO *sha_info)
-{
- digest[ 0] = (unsigned char) ((sha_info->digest[0] >> 24) & 0xff);
- digest[ 1] = (unsigned char) ((sha_info->digest[0] >> 16) & 0xff);
- digest[ 2] = (unsigned char) ((sha_info->digest[0] >> 8) & 0xff);
- digest[ 3] = (unsigned char) ((sha_info->digest[0] ) & 0xff);
- digest[ 4] = (unsigned char) ((sha_info->digest[1] >> 24) & 0xff);
- digest[ 5] = (unsigned char) ((sha_info->digest[1] >> 16) & 0xff);
- digest[ 6] = (unsigned char) ((sha_info->digest[1] >> 8) & 0xff);
- digest[ 7] = (unsigned char) ((sha_info->digest[1] ) & 0xff);
- digest[ 8] = (unsigned char) ((sha_info->digest[2] >> 24) & 0xff);
- digest[ 9] = (unsigned char) ((sha_info->digest[2] >> 16) & 0xff);
- digest[10] = (unsigned char) ((sha_info->digest[2] >> 8) & 0xff);
- digest[11] = (unsigned char) ((sha_info->digest[2] ) & 0xff);
- digest[12] = (unsigned char) ((sha_info->digest[3] >> 24) & 0xff);
- digest[13] = (unsigned char) ((sha_info->digest[3] >> 16) & 0xff);
- digest[14] = (unsigned char) ((sha_info->digest[3] >> 8) & 0xff);
- digest[15] = (unsigned char) ((sha_info->digest[3] ) & 0xff);
- digest[16] = (unsigned char) ((sha_info->digest[4] >> 24) & 0xff);
- digest[17] = (unsigned char) ((sha_info->digest[4] >> 16) & 0xff);
- digest[18] = (unsigned char) ((sha_info->digest[4] >> 8) & 0xff);
- digest[19] = (unsigned char) ((sha_info->digest[4] ) & 0xff);
- digest[20] = (unsigned char) ((sha_info->digest[5] >> 24) & 0xff);
- digest[21] = (unsigned char) ((sha_info->digest[5] >> 16) & 0xff);
- digest[22] = (unsigned char) ((sha_info->digest[5] >> 8) & 0xff);
- digest[23] = (unsigned char) ((sha_info->digest[5] ) & 0xff);
- digest[24] = (unsigned char) ((sha_info->digest[6] >> 24) & 0xff);
- digest[25] = (unsigned char) ((sha_info->digest[6] >> 16) & 0xff);
- digest[26] = (unsigned char) ((sha_info->digest[6] >> 8) & 0xff);
- digest[27] = (unsigned char) ((sha_info->digest[6] ) & 0xff);
- digest[28] = (unsigned char) ((sha_info->digest[7] >> 24) & 0xff);
- digest[29] = (unsigned char) ((sha_info->digest[7] >> 16) & 0xff);
- digest[30] = (unsigned char) ((sha_info->digest[7] >> 8) & 0xff);
- digest[31] = (unsigned char) ((sha_info->digest[7] ) & 0xff);
-}
-
-
-/***EOF***/
View
10 perl/FKO/lib/FKO.pm
@@ -16,7 +16,7 @@ use warnings;
use Carp;
require Exporter;
-our $VERSION = '0.22';
+our $VERSION = '0.23';
our @ISA = qw(Exporter);
@@ -706,6 +706,14 @@ The SHA1 message digest algorithm.
The SHA256 message digest algorithm. This is the I<libfko> default.
+=item * B<FKO_DIGEST_SHA384>
+
+The SHA384 message digest algorithm. This is the I<libfko> default.
+
+=item * B<FKO_DIGEST_SHA512>
+
+The SHA512 message digest algorithm. This is the I<libfko> default.
+
=back
View
4 perl/FKO/lib/FKO_Constants.pl
@@ -27,6 +27,8 @@
FKO_DIGEST_MD5
FKO_DIGEST_SHA1
FKO_DIGEST_SHA256
+ FKO_DIGEST_SHA384
+ FKO_DIGEST_SHA512
);
# Encryption types tag list.
@@ -101,6 +103,8 @@
FKO_DIGEST_MD5 => 1,
FKO_DIGEST_SHA1 => 2,
FKO_DIGEST_SHA256 => 3,
+ FKO_DIGEST_SHA384 => 4,
+ FKO_DIGEST_SHA512 => 5,
# Encryption types
FKO_ENCRYPTION_RIJNDAEL => 1,
View
14 src/config_init.c
@@ -77,11 +77,15 @@ get_char_val(const char *var_name, char *dest, char *lptr)
static int
parse_time_offset(char *offset_str)
{
- int offset = 0, i, j, offset_type = TIME_OFFSET_SECONDS;
+ int i, j;
+ int offset = 0;
+ int offset_type = TIME_OFFSET_SECONDS;
+ int os_len = strlen(offset_str);
+
char offset_digits[MAX_TIME_STR_LEN];
j=0;
- for (i=0; i < strlen(offset_str); i++) {
+ for (i=0; i < os_len; i++) {
if (isdigit(offset_str[i])) {
offset_digits[j] = offset_str[i];
j++;
@@ -247,7 +251,7 @@ validate_options(fko_cli_options_t *options)
void
config_init(fko_cli_options_t *options, int argc, char **argv)
{
- int cmd_arg, index, i;
+ int cmd_arg, index;
struct opts_track ot;
/* Zero out options and opts_track.
@@ -309,6 +313,10 @@ config_init(fko_cli_options_t *options, int argc, char **argv)
options->digest_type = FKO_DIGEST_SHA1;
else if(strncasecmp(optarg, "sha256", 6) == 0)
options->digest_type = FKO_DIGEST_SHA256;
+ else if(strncasecmp(optarg, "sha384", 6) == 0)
+ options->digest_type = FKO_DIGEST_SHA384;
+ else if(strncasecmp(optarg, "sha512", 6) == 0)
+ options->digest_type = FKO_DIGEST_SHA512;
else
{
fprintf(stderr, "* Invalid digest type: %s\n", optarg);
View
6 src/fwknop.c
@@ -431,8 +431,9 @@ static int
ipv4_str_has_port(char *str)
{
int rv = 0, i;
+ int st_len = strlen(str);
- for (i=0; i < strlen(str); i++) {
+ for (i=0; i < st_len; i++) {
if (str[i] == ',' || str[i] == ':') {
str[i] = ','; /* force "<ip>,<port>" format */
rv = 1;
@@ -453,7 +454,6 @@ static void resolve_ip_http(fko_cli_options_t *options)
struct addrinfo *result, *rp, hints;
char http_buf[HTTP_MAX_REQUEST_LEN];
char http_response[HTTP_MAX_RESPONSE_LEN];
- char ip_str[MAX_IP_STR_LEN];
/* Build our HTTP request to resolve the external IP (this is similar to
* to contacting whatismyip.org, but using a different URL).
@@ -520,7 +520,7 @@ static void resolve_ip_http(fko_cli_options_t *options)
);
}
- res = read(sock, http_response, HTTP_MAX_RESPONSE_LEN);
+ res = recv(sock, http_response, HTTP_MAX_RESPONSE_LEN, 0);
http_response[HTTP_MAX_RESPONSE_LEN-1] = '\0';
#ifdef WIN32

0 comments on commit 7f45031

Please sign in to comment.