loudmouth/lm-sha.c
author Mikael Berthe <mikael@lilotux.net>
Thu, 05 Nov 2015 21:47:40 +0100
changeset 672 71f60c55efb3
parent 518 cdd6a0c5b439
child 681 e3370fbe0a25
permissions -rw-r--r--
Update release information files Change the maintainers.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     1
/*-
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     2
 * Copyright (c) 2001, 2002 Allan Saddi <allan@saddi.com>
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     3
 * All rights reserved.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     4
 *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     5
 * Redistribution and use in source and binary forms, with or without
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     6
 * modification, are permitted provided that the following conditions
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     7
 * are met:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     8
 * 1. Redistributions of source code must retain the above copyright
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     9
 *    notice, this list of conditions and the following disclaimer.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    10
 * 2. Redistributions in binary form must reproduce the above copyright
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    11
 *    notice, this list of conditions and the following disclaimer in the
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    12
 *    documentation and/or other materials provided with the distribution.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    13
 *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    14
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    15
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    17
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    18
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    19
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    20
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    21
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    22
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    23
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    24
 * SUCH DAMAGE.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    25
 *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    26
 */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    27
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    28
/*
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    29
 * Define WORDS_BIGENDIAN if compiling on a big-endian architecture.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    30
 *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    31
 * Define SHA1_TEST to test the implementation using the NIST's
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    32
 * sample messages. The output should be:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    33
 *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    34
 *   a9993e36 4706816a ba3e2571 7850c26c 9cd0d89d
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    35
 *   84983e44 1c3bd26e baae4aa1 f95129e5 e54670f1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    36
 *   34aa973c d4c4daa4 f61eeb2b dbad2731 6534016f
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    37
 */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    38
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    39
#ifdef HAVE_CONFIG_H
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    40
#include <config.h>
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    41
#endif /* HAVE_CONFIG_H */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    42
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    43
#include <string.h>
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    44
#include <stdio.h>
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    45
#include <glib.h>
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    46
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    47
#include "lm-sha.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    48
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    49
#define SHA1_HASH_SIZE 20
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    50
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    51
/* Hash size in 32-bit words */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    52
#define SHA1_HASH_WORDS 5
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    53
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    54
struct _SHA1Context {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
    55
        guint64 totalLength;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
    56
        guint32 hash[SHA1_HASH_WORDS];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
    57
        guint32 bufferLength;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
    58
        union {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
    59
                guint32 words[16];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
    60
                guint8 bytes[64];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
    61
        } buffer;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    62
};
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    63
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    64
typedef struct _SHA1Context SHA1Context;
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    65
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    66
#ifdef __cplusplus
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    67
extern "C" {
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    68
#endif
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    69
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
    70
        static void SHA1Init (SHA1Context *sc);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
    71
        static void SHA1Update (SHA1Context *sc, const void *udata, guint32 len);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
    72
        static void SHA1Final (SHA1Context *sc, guint8 hash[SHA1_HASH_SIZE]);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    73
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    74
#ifdef __cplusplus
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    75
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    76
#endif
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    77
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    78
#ifndef lint
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    79
static const char rcsid[] =
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
    80
"$Id$";
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    81
#endif /* !lint */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    82
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    83
#define ROTL(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    84
#define ROTR(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    85
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    86
#define F_0_19(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    87
#define F_20_39(x, y, z) ((x) ^ (y) ^ (z))
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    88
#define F_40_59(x, y, z) (((x) & ((y) | (z))) | ((y) & (z)))
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    89
#define F_60_79(x, y, z) ((x) ^ (y) ^ (z))
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    90
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    91
#define DO_ROUND(F, K) { \
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    92
  temp = ROTL(a, 5) + F(b, c, d) + e + *(W++) + K; \
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    93
  e = d; \
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    94
  d = c; \
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    95
  c = ROTL(b, 30); \
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    96
  b = a; \
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    97
  a = temp; \
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    98
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    99
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   100
#define K_0_19 0x5a827999L
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   101
#define K_20_39 0x6ed9eba1L
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   102
#define K_40_59 0x8f1bbcdcL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   103
#define K_60_79 0xca62c1d6L
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   104
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   105
#ifndef RUNTIME_ENDIAN
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   106
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   107
#ifdef WORDS_BIGENDIAN
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   108
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   109
#define BYTESWAP(x) (x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   110
#define BYTESWAP64(x) (x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   111
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   112
#else /* WORDS_BIGENDIAN */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   113
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   114
#define BYTESWAP(x) ((ROTR((x), 8) & 0xff00ff00L) | \
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   115
                     (ROTL((x), 8) & 0x00ff00ffL))
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   116
#define BYTESWAP64(x) _byteswap64(x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   117
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   118
static inline guint64 _byteswap64(guint64 x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   119
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   120
        guint32 a = x >> 32;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   121
        guint32 b = (guint32) x;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   122
        return ((guint64) BYTESWAP(b) << 32) | (guint64) BYTESWAP(a);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   123
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   124
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   125
#endif /* WORDS_BIGENDIAN */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   126
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   127
#else /* !RUNTIME_ENDIAN */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   128
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   129
static int littleEndian;
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   130
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   131
#define BYTESWAP(x) _byteswap(x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   132
#define BYTESWAP64(x) _byteswap64(x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   133
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   134
#define _BYTESWAP(x) ((ROTR((x), 8) & 0xff00ff00L) | \
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   135
                      (ROTL((x), 8) & 0x00ff00ffL))
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   136
#define _BYTESWAP64(x) __byteswap64(x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   137
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   138
static inline guint64 __byteswap64(guint64 x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   139
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   140
        guint32 a = x >> 32;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   141
        guint32 b = (guint32) x;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   142
        return ((guint64) _BYTESWAP(b) << 32) | (guint64) _BYTESWAP(a);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   143
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   144
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   145
static inline guint32 _byteswap(guint32 x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   146
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   147
        if (!littleEndian)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   148
                return x;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   149
        else
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   150
                return _BYTESWAP(x);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   151
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   152
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   153
static inline guint64 _byteswap64(guint64 x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   154
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   155
        if (!littleEndian)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   156
                return x;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   157
        else
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   158
                return _BYTESWAP64(x);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   159
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   160
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   161
static inline void setEndian(void)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   162
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   163
        union {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   164
                guint32 w;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   165
                guint8 b[4];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   166
        } endian;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   167
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   168
        endian.w = 1L;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   169
        littleEndian = endian.b[0] != 0;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   170
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   171
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   172
#endif /* !RUNTIME_ENDIAN */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   173
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   174
static const guint8 padding[64] = {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   175
        0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   176
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   177
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   178
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   179
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   180
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   181
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   182
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   183
};
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   184
162
16d29898f97b 2006-08-03 Richard Hult <richard@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   185
static void
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   186
SHA1Init (SHA1Context *sc)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   187
{
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   188
#ifdef RUNTIME_ENDIAN
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   189
        setEndian ();
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   190
#endif /* RUNTIME_ENDIAN */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   191
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 86
diff changeset
   192
#ifdef G_OS_WIN32
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   193
        sc->totalLength = 0L;
9
2e14e3ab411b 2003-06-24 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 1
diff changeset
   194
#else
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   195
        sc->totalLength = 0LL;
9
2e14e3ab411b 2003-06-24 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 1
diff changeset
   196
#endif
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   197
        sc->hash[0] = 0x67452301L;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   198
        sc->hash[1] = 0xefcdab89L;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   199
        sc->hash[2] = 0x98badcfeL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   200
        sc->hash[3] = 0x10325476L;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   201
        sc->hash[4] = 0xc3d2e1f0L;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   202
        sc->bufferLength = 0L;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   203
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   204
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   205
static void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   206
burnStack (int size)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   207
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   208
        char buf[128];
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   209
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   210
        memset (buf, 0, sizeof (buf));
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   211
        size -= sizeof (buf);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   212
        if (size > 0)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   213
                burnStack (size);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   214
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   215
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   216
static void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   217
SHA1Guts (SHA1Context *sc, const guint32 *cbuf)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   218
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   219
        guint32 buf[80];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   220
        guint32 *W, *W3, *W8, *W14, *W16;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   221
        guint32 a, b, c, d, e, temp;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   222
        int i;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   223
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   224
        W = buf;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   225
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   226
        for (i = 15; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   227
                *(W++) = BYTESWAP(*cbuf);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   228
                cbuf++;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   229
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   230
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   231
        W16 = &buf[0];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   232
        W14 = &buf[2];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   233
        W8 = &buf[8];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   234
        W3 = &buf[13];
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   235
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   236
        for (i = 63; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   237
                *W = *(W3++) ^ *(W8++) ^ *(W14++) ^ *(W16++);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   238
                *W = ROTL(*W, 1);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   239
                W++;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   240
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   241
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   242
        a = sc->hash[0];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   243
        b = sc->hash[1];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   244
        c = sc->hash[2];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   245
        d = sc->hash[3];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   246
        e = sc->hash[4];
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   247
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   248
        W = buf;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   249
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   250
#ifndef SHA1_UNROLL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   251
#define SHA1_UNROLL 20
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   252
#endif /* !SHA1_UNROLL */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   253
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   254
#if SHA1_UNROLL == 1
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   255
        for (i = 19; i >= 0; i--)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   256
                DO_ROUND(F_0_19, K_0_19);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   257
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   258
        for (i = 19; i >= 0; i--)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   259
                DO_ROUND(F_20_39, K_20_39);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   260
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   261
        for (i = 19; i >= 0; i--)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   262
                DO_ROUND(F_40_59, K_40_59);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   263
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   264
        for (i = 19; i >= 0; i--)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   265
                DO_ROUND(F_60_79, K_60_79);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   266
#elif SHA1_UNROLL == 2
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   267
        for (i = 9; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   268
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   269
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   270
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   271
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   272
        for (i = 9; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   273
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   274
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   275
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   276
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   277
        for (i = 9; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   278
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   279
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   280
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   281
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   282
        for (i = 9; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   283
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   284
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   285
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   286
#elif SHA1_UNROLL == 4
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   287
        for (i = 4; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   288
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   289
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   290
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   291
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   292
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   293
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   294
        for (i = 4; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   295
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   296
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   297
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   298
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   299
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   300
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   301
        for (i = 4; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   302
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   303
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   304
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   305
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   306
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   307
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   308
        for (i = 4; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   309
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   310
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   311
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   312
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   313
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   314
#elif SHA1_UNROLL == 5
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   315
        for (i = 3; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   316
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   317
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   318
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   319
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   320
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   321
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   322
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   323
        for (i = 3; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   324
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   325
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   326
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   327
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   328
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   329
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   330
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   331
        for (i = 3; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   332
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   333
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   334
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   335
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   336
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   337
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   338
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   339
        for (i = 3; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   340
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   341
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   342
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   343
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   344
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   345
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   346
#elif SHA1_UNROLL == 10
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   347
        for (i = 1; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   348
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   349
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   350
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   351
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   352
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   353
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   354
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   355
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   356
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   357
                DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   358
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   359
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   360
        for (i = 1; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   361
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   362
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   363
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   364
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   365
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   366
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   367
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   368
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   369
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   370
                DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   371
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   372
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   373
        for (i = 1; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   374
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   375
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   376
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   377
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   378
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   379
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   380
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   381
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   382
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   383
                DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   384
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   385
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   386
        for (i = 1; i >= 0; i--) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   387
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   388
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   389
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   390
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   391
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   392
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   393
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   394
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   395
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   396
                DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   397
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   398
#elif SHA1_UNROLL == 20
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   399
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   400
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   401
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   402
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   403
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   404
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   405
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   406
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   407
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   408
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   409
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   410
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   411
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   412
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   413
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   414
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   415
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   416
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   417
        DO_ROUND(F_0_19, K_0_19);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   418
        DO_ROUND(F_0_19, K_0_19);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   419
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   420
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   421
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   422
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   423
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   424
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   425
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   426
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   427
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   428
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   429
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   430
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   431
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   432
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   433
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   434
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   435
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   436
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   437
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   438
        DO_ROUND(F_20_39, K_20_39);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   439
        DO_ROUND(F_20_39, K_20_39);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   440
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   441
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   442
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   443
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   444
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   445
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   446
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   447
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   448
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   449
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   450
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   451
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   452
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   453
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   454
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   455
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   456
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   457
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   458
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   459
        DO_ROUND(F_40_59, K_40_59);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   460
        DO_ROUND(F_40_59, K_40_59);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   461
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   462
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   463
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   464
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   465
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   466
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   467
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   468
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   469
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   470
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   471
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   472
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   473
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   474
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   475
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   476
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   477
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   478
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   479
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   480
        DO_ROUND(F_60_79, K_60_79);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   481
        DO_ROUND(F_60_79, K_60_79);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   482
#else /* SHA1_UNROLL */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   483
#error SHA1_UNROLL must be 1, 2, 4, 5, 10 or 20!
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   484
#endif
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   485
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   486
        sc->hash[0] += a;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   487
        sc->hash[1] += b;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   488
        sc->hash[2] += c;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   489
        sc->hash[3] += d;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   490
        sc->hash[4] += e;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   491
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   492
162
16d29898f97b 2006-08-03 Richard Hult <richard@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   493
static void
84
7ae7b690aa89 2004-05-28 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 9
diff changeset
   494
SHA1Update (SHA1Context *sc, const void *udata, guint32 len)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   495
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   496
        guint32 bufferBytesLeft;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   497
        guint32 bytesToCopy;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   498
        int needBurn = 0;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   499
        guint8 *data = (guint8 *)udata;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   500
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   501
#ifdef SHA1_FAST_COPY
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   502
        if (sc->bufferLength) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   503
                bufferBytesLeft = 64L - sc->bufferLength;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   504
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   505
                bytesToCopy = bufferBytesLeft;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   506
                if (bytesToCopy > len)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   507
                        bytesToCopy = len;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   508
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   509
                memcpy (&sc->buffer.bytes[sc->bufferLength], data, bytesToCopy);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   510
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   511
                sc->totalLength += bytesToCopy * 8L;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   512
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   513
                sc->bufferLength += bytesToCopy;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   514
                data += bytesToCopy;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   515
                len -= bytesToCopy;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   516
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   517
                if (sc->bufferLength == 64L) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   518
                        SHA1Guts (sc, sc->buffer.words);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   519
                        needBurn = 1;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   520
                        sc->bufferLength = 0L;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   521
                }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   522
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   523
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   524
        while (len > 63) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   525
                sc->totalLength += 512L;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   526
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   527
                SHA1Guts (sc, data);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   528
                needBurn = 1;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   529
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   530
                data += 64L;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   531
                len -= 64L;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   532
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   533
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   534
        if (len) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   535
                memcpy (&sc->buffer.bytes[sc->bufferLength], data, len);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   536
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   537
                sc->totalLength += len * 8L;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   538
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   539
                sc->bufferLength += len;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   540
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   541
#else /* SHA1_FAST_COPY */
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   542
        while (len) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   543
                bufferBytesLeft = 64L - sc->bufferLength;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   544
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   545
                bytesToCopy = bufferBytesLeft;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   546
                if (bytesToCopy > len)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   547
                        bytesToCopy = len;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   548
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   549
                memcpy (&sc->buffer.bytes[sc->bufferLength], data, bytesToCopy);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   550
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   551
                sc->totalLength += bytesToCopy * 8L;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   552
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   553
                sc->bufferLength += bytesToCopy;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   554
                data += bytesToCopy;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   555
                len -= bytesToCopy;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   556
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   557
                if (sc->bufferLength == 64L) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   558
                        SHA1Guts (sc, sc->buffer.words);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   559
                        needBurn = 1;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   560
                        sc->bufferLength = 0L;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   561
                }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   562
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   563
#endif /* SHA1_FAST_COPY */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   564
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   565
        if (needBurn)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   566
                burnStack (sizeof (guint32[86]) + sizeof (guint32 *[5]) + sizeof (int));
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   567
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   568
162
16d29898f97b 2006-08-03 Richard Hult <richard@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   569
static void
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   570
SHA1Final (SHA1Context *sc, guint8 hash[SHA1_HASH_SIZE])
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   571
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   572
        guint32 bytesToPad;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   573
        guint64 lengthPad;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   574
        int i;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   575
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   576
        bytesToPad = 120L - sc->bufferLength;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   577
        if (bytesToPad > 64L)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   578
                bytesToPad -= 64L;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   579
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   580
        lengthPad = BYTESWAP64(sc->totalLength);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   581
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   582
        SHA1Update (sc, padding, bytesToPad);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   583
        SHA1Update (sc, &lengthPad, 8L);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   584
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   585
        if (hash) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   586
                for (i = 0; i < SHA1_HASH_WORDS; i++) {
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   587
#ifdef SHA1_FAST_COPY
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   588
                        *((guint32 *) hash) = BYTESWAP(sc->hash[i]);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   589
#else /* SHA1_FAST_COPY */
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   590
                        hash[0] = (guint8) (sc->hash[i] >> 24);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   591
                        hash[1] = (guint8) (sc->hash[i] >> 16);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   592
                        hash[2] = (guint8) (sc->hash[i] >> 8);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   593
                        hash[3] = (guint8) sc->hash[i];
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   594
#endif /* SHA1_FAST_COPY */
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   595
                        hash += 4;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   596
                }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   597
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   598
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   599
497
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   600
/**
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   601
 * lm_sha_hash:
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   602
 * @str: the input string
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   603
 *
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   604
 * Computes the SHA1 checksum of @str and prints it in text mode.
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   605
 *
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   606
 * Return value: A newly allocated string.
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   607
 **/
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   608
gchar *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   609
lm_sha_hash (const gchar *str)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   610
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   611
        gchar        *ret_val;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   612
        SHA1Context   ctx;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   613
        guint8        hash[SHA1_HASH_SIZE];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   614
        gchar        *ch;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   615
        guint         i;
497
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   616
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   617
        ret_val = g_malloc (SHA1_HASH_SIZE*2 + 1);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   618
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   619
        SHA1Init (&ctx);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   620
        SHA1Update (&ctx, str, strlen (str));
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   621
        SHA1Final (&ctx, hash);
497
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   622
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   623
        ch = ret_val;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   624
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   625
        for (i = 0; i < SHA1_HASH_SIZE; ++i) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   626
                g_snprintf (ch, 3, "%02x", hash[i]);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   627
                ch += 2;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   628
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   629
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   630
        return ret_val;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   631
}