loudmouth/lm-sha.c
author Frank Zschockelt <lm@freakysoft.de>
Mon, 13 May 2019 22:09:10 +0200
changeset 739 4a32df98ff8c
parent 681 e3370fbe0a25
permissions -rw-r--r--
g_type_class_add_private is deprecated since glib 2.58
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
#define ROTL(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    79
#define ROTR(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    80
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    81
#define F_0_19(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    82
#define F_20_39(x, y, z) ((x) ^ (y) ^ (z))
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    83
#define F_40_59(x, y, z) (((x) & ((y) | (z))) | ((y) & (z)))
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    84
#define F_60_79(x, y, z) ((x) ^ (y) ^ (z))
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    85
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    86
#define DO_ROUND(F, K) { \
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    87
  temp = ROTL(a, 5) + F(b, c, d) + e + *(W++) + K; \
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    88
  e = d; \
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    89
  d = c; \
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    90
  c = ROTL(b, 30); \
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    91
  b = a; \
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    92
  a = temp; \
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    93
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    94
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    95
#define K_0_19 0x5a827999L
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    96
#define K_20_39 0x6ed9eba1L
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    97
#define K_40_59 0x8f1bbcdcL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    98
#define K_60_79 0xca62c1d6L
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    99
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   100
#ifndef RUNTIME_ENDIAN
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   101
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   102
#ifdef WORDS_BIGENDIAN
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   103
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   104
#define BYTESWAP(x) (x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   105
#define BYTESWAP64(x) (x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   106
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   107
#else /* WORDS_BIGENDIAN */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   108
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   109
#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
   110
                     (ROTL((x), 8) & 0x00ff00ffL))
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   111
#define BYTESWAP64(x) _byteswap64(x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   112
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   113
static inline guint64 _byteswap64(guint64 x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   114
{
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
        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
   116
        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
   117
        return ((guint64) BYTESWAP(b) << 32) | (guint64) BYTESWAP(a);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   118
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   119
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   120
#endif /* WORDS_BIGENDIAN */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   121
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   122
#else /* !RUNTIME_ENDIAN */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   123
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   124
static int littleEndian;
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   125
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   126
#define BYTESWAP(x) _byteswap(x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   127
#define BYTESWAP64(x) _byteswap64(x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   128
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   129
#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
   130
                      (ROTL((x), 8) & 0x00ff00ffL))
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   131
#define _BYTESWAP64(x) __byteswap64(x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   132
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   133
static inline guint64 __byteswap64(guint64 x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   134
{
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
        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
   136
        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
   137
        return ((guint64) _BYTESWAP(b) << 32) | (guint64) _BYTESWAP(a);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   138
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   139
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   140
static inline guint32 _byteswap(guint32 x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   141
{
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
   142
        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
   143
                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
   144
        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
   145
                return _BYTESWAP(x);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   146
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   147
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   148
static inline guint64 _byteswap64(guint64 x)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   149
{
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
   150
        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
   151
                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
   152
        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
   153
                return _BYTESWAP64(x);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   154
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   155
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   156
static inline void setEndian(void)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   157
{
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
   158
        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
   159
                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
   160
                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
   161
        } endian;
1
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
        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
   164
        littleEndian = endian.b[0] != 0;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   165
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   166
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   167
#endif /* !RUNTIME_ENDIAN */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   168
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   169
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
   170
        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
   171
        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
   172
        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
   173
        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
   174
        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
   175
        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
   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
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   178
};
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   179
162
16d29898f97b 2006-08-03 Richard Hult <richard@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   180
static void
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   181
SHA1Init (SHA1Context *sc)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   182
{
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   183
#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
   184
        setEndian ();
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   185
#endif /* RUNTIME_ENDIAN */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   186
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 86
diff changeset
   187
#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
   188
        sc->totalLength = 0L;
9
2e14e3ab411b 2003-06-24 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 1
diff changeset
   189
#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
   190
        sc->totalLength = 0LL;
9
2e14e3ab411b 2003-06-24 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 1
diff changeset
   191
#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
   192
        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
   193
        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
   194
        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
   195
        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
   196
        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
   197
        sc->bufferLength = 0L;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   198
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   199
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   200
static void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   201
burnStack (int size)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   202
{
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
   203
        char buf[128];
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   204
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
   205
        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
   206
        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
   207
        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
   208
                burnStack (size);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   209
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   210
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   211
static void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   212
SHA1Guts (SHA1Context *sc, const guint32 *cbuf)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   213
{
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
   214
        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
   215
        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
   216
        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
   217
        int i;
1
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
        W = buf;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   220
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
   221
        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
   222
                *(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
   223
                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
   224
        }
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
        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
   227
        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
   228
        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
   229
        W3 = &buf[13];
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
        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
   232
                *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
   233
                *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
   234
                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
   235
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   236
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
   237
        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
   238
        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
   239
        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
   240
        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
   241
        e = sc->hash[4];
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   242
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
   243
        W = buf;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   244
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   245
#ifndef SHA1_UNROLL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   246
#define SHA1_UNROLL 20
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   247
#endif /* !SHA1_UNROLL */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   248
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   249
#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
   250
        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
   251
                DO_ROUND(F_0_19, K_0_19);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   252
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
   253
        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
   254
                DO_ROUND(F_20_39, K_20_39);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   255
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
   256
        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
   257
                DO_ROUND(F_40_59, K_40_59);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   258
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
   259
        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
   260
                DO_ROUND(F_60_79, K_60_79);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   261
#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
   262
        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
   263
                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
   264
                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
   265
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   266
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_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
   269
                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
   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_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
   274
                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
   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_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
   279
                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
   280
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   281
#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
   282
        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
   283
                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
   284
                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
   285
                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
   286
                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
   287
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   288
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
   289
        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
   290
                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
   291
                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
   292
                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
   293
                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
   294
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   295
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
   296
        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
   297
                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
   298
                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
   299
                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
   300
                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
   301
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   302
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
   303
        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
   304
                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
   305
                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
   306
                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
   307
                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
   308
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   309
#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
   310
        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
   311
                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
   312
                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
   313
                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
   314
                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
   315
                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
   316
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   317
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
   318
        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
   319
                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
   320
                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
   321
                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
   322
                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
   323
                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
   324
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   325
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
   326
        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
   327
                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
   328
                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
   329
                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
   330
                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
   331
                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
   332
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   333
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
   334
        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
   335
                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
   336
                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
   337
                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
   338
                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
   339
                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
   340
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   341
#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
   342
        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
   343
                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
   344
                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
   345
                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
   346
                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
   347
                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
   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
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   354
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
   355
        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
   356
                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
   357
                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
   358
                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
   359
                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
   360
                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
   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
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   367
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
   368
        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
   369
                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
   370
                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
   371
                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
   372
                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
   373
                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
   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
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   380
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
   381
        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
   382
                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
   383
                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
   384
                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
   385
                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
   386
                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
   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
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   393
#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
   394
        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
   395
        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
   396
        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
   397
        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
   398
        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
   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);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   414
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
   415
        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
   416
        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
   417
        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
   418
        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
   419
        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
   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);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   435
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
   436
        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
   437
        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
   438
        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
   439
        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
   440
        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
   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);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   456
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
   457
        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
   458
        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
   459
        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
   460
        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
   461
        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
   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);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   477
#else /* SHA1_UNROLL */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   478
#error SHA1_UNROLL must be 1, 2, 4, 5, 10 or 20!
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   479
#endif
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   480
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
   481
        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
   482
        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
   483
        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
   484
        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
   485
        sc->hash[4] += e;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   486
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   487
162
16d29898f97b 2006-08-03 Richard Hult <richard@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   488
static void
84
7ae7b690aa89 2004-05-28 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 9
diff changeset
   489
SHA1Update (SHA1Context *sc, const void *udata, guint32 len)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   490
{
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
   491
        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
   492
        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
   493
        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
   494
        guint8 *data = (guint8 *)udata;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   495
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   496
#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
   497
        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
   498
                bufferBytesLeft = 64L - sc->bufferLength;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   499
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
   500
                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
   501
                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
   502
                        bytesToCopy = len;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   503
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
   504
                memcpy (&sc->buffer.bytes[sc->bufferLength], data, bytesToCopy);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   505
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
   506
                sc->totalLength += bytesToCopy * 8L;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   507
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
   508
                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
   509
                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
   510
                len -= bytesToCopy;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   511
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
   512
                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
   513
                        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
   514
                        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
   515
                        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
   516
                }
cdd6a0c5b439 Went 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
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   518
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
   519
        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
   520
                sc->totalLength += 512L;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   521
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
   522
                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
   523
                needBurn = 1;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   524
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
   525
                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
   526
                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
   527
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   528
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
   529
        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
   530
                memcpy (&sc->buffer.bytes[sc->bufferLength], data, len);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   531
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
   532
                sc->totalLength += len * 8L;
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
                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
   535
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   536
#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
   537
        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
   538
                bufferBytesLeft = 64L - sc->bufferLength;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   539
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
   540
                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
   541
                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
   542
                        bytesToCopy = len;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   543
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
   544
                memcpy (&sc->buffer.bytes[sc->bufferLength], data, bytesToCopy);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   545
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
   546
                sc->totalLength += bytesToCopy * 8L;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   547
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
   548
                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
   549
                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
   550
                len -= bytesToCopy;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   551
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
   552
                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
   553
                        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
   554
                        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
   555
                        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
   556
                }
cdd6a0c5b439 Went 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
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   558
#endif /* SHA1_FAST_COPY */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   559
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
   560
        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
   561
                burnStack (sizeof (guint32[86]) + sizeof (guint32 *[5]) + sizeof (int));
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   562
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   563
162
16d29898f97b 2006-08-03 Richard Hult <richard@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   564
static void
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   565
SHA1Final (SHA1Context *sc, guint8 hash[SHA1_HASH_SIZE])
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   566
{
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
   567
        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
   568
        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
   569
        int i;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   570
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
   571
        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
   572
        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
   573
                bytesToPad -= 64L;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   574
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
   575
        lengthPad = BYTESWAP64(sc->totalLength);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   576
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
   577
        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
   578
        SHA1Update (sc, &lengthPad, 8L);
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
        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
   581
                for (i = 0; i < SHA1_HASH_WORDS; i++) {
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   582
#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
   583
                        *((guint32 *) hash) = BYTESWAP(sc->hash[i]);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   584
#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
   585
                        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
   586
                        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
   587
                        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
   588
                        hash[3] = (guint8) sc->hash[i];
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   589
#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
   590
                        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
   591
                }
cdd6a0c5b439 Went 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
        }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   593
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   594
497
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   595
/**
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   596
 * lm_sha_hash:
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   597
 * @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
   598
 *
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   599
 * 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
   600
 *
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   601
 * 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
   602
 **/
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   603
gchar *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   604
lm_sha_hash (const gchar *str)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   605
{
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
   606
        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
   607
        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
   608
        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
   609
        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
   610
        guint         i;
497
bb4157a604ec Make lm_sha_hash thread safe. Fixes LM-64
Andreas Köhler <andi5.py@gmx.net>
parents: 162
diff changeset
   611
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
   612
        ret_val = g_malloc (SHA1_HASH_SIZE*2 + 1);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   613
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
   614
        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
   615
        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
   616
        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
   617
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
   618
        ch = ret_val;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   619
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
   620
        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
   621
                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
   622
                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
   623
        }
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
        return ret_val;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   626
}