Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
sha512.c File Reference
#include "prcpucfg.h"
#include "prtypes.h"
#include "secport.h"
#include "blapi.h"
#include "sha256.h"

Go to the source code of this file.

Classes

struct  SHA512ContextStr
union  SHA512ContextStr.u

Defines

#define W   ctx->u.w
#define B   ctx->u.b
#define H   ctx->h
#define SHR(x, n)   (x >> n)
#define SHL(x, n)   (x << n)
#define Ch(x, y, z)   ((x & y) ^ (~x & z))
#define Maj(x, y, z)   ((x & y) ^ (x & z) ^ (y & z))
#define SWAP4MASK   0x00FF00FF
#define SHA_HTONL(x)
#define BYTESWAP4(x)   x = SHA_HTONL(x)
#define ROTR32(x, n)   ((x >> n) | (x << ((8 * sizeof x) - n)))
#define ROTL32(x, n)   ((x << n) | (x >> ((8 * sizeof x) - n)))
#define S0(x)   (ROTR32(x, 2) ^ ROTR32(x,13) ^ ROTR32(x,22))
#define S1(x)   (ROTR32(x, 6) ^ ROTR32(x,11) ^ ROTR32(x,25))
#define s0(x)   (t1 = x, ROTR32(t1, 7) ^ ROTR32(t1,18) ^ SHR(t1, 3))
#define s1(x)   (t2 = x, ROTR32(t2,17) ^ ROTR32(t2,19) ^ SHR(t2,10))
#define INITW(t)   W[t] = (s1(W[t-2]) + W[t-7] + s0(W[t-15]) + W[t-16])
#define ROUND(n, a, b, c, d, e, f, g, h)
#define ULLC(hi, lo)   { 0x ## hi ## U, 0x ## lo ## U }
#define SHA_HTONLL(x)
#define BYTESWAP8(x)
#define DUMP(n, a, d, e, h)
#define NOUNROLL512   1
#define ADDTO(x, y)   y.lo += x.lo; y.hi += x.hi + (x.lo > y.lo)
#define ROTR64a(x, n, lo, hi)   (x.lo >> n | x.hi << (32-n))
#define ROTR64A(x, n, lo, hi)   (x.lo << (64-n) | x.hi >> (n-32))
#define SHR64a(x, n, lo, hi)   (x.lo >> n | x.hi << (32-n))
#define s0lo(x)   (ROTR64a(x,1,lo,hi) ^ ROTR64a(x,8,lo,hi) ^ SHR64a(x,7,lo,hi))
#define s0hi(x)   (ROTR64a(x,1,hi,lo) ^ ROTR64a(x,8,hi,lo) ^ (x.hi >> 7))
#define s1lo(x)   (ROTR64a(x,19,lo,hi) ^ ROTR64A(x,61,lo,hi) ^ SHR64a(x,6,lo,hi))
#define s1hi(x)   (ROTR64a(x,19,hi,lo) ^ ROTR64A(x,61,hi,lo) ^ (x.hi >> 6))
#define S0lo(x)   (ROTR64a(x,28,lo,hi) ^ ROTR64A(x,34,lo,hi) ^ ROTR64A(x,39,lo,hi))
#define S0hi(x)   (ROTR64a(x,28,hi,lo) ^ ROTR64A(x,34,hi,lo) ^ ROTR64A(x,39,hi,lo))
#define S1lo(x)   (ROTR64a(x,14,lo,hi) ^ ROTR64a(x,18,lo,hi) ^ ROTR64A(x,41,lo,hi))
#define S1hi(x)   (ROTR64a(x,14,hi,lo) ^ ROTR64a(x,18,hi,lo) ^ ROTR64A(x,41,hi,lo))
#define Chxx(x, y, z, lo)   ((x.lo & y.lo) ^ (~x.lo & z.lo))
#define Majx(x, y, z, lo)   ((x.lo & y.lo) ^ (x.lo & z.lo) ^ (y.lo & z.lo))
#define INITW(t)
#define ROUND(n, a, b, c, d, e, f, g, h)
#define SHA_MIN(a, b)   (a < b ? a : b)

Functions

SHA256Context * SHA256_NewContext (void)
void SHA256_DestroyContext (SHA256Context *ctx, PRBool freeit)
void SHA256_Begin (SHA256Context *ctx)
static void SHA256_Compress (SHA256Context *ctx)
void SHA256_Update (SHA256Context *ctx, const unsigned char *input, unsigned int inputLen)
void SHA256_End (SHA256Context *ctx, unsigned char *digest, unsigned int *digestLen, unsigned int maxDigestLen)
SECStatus SHA256_HashBuf (unsigned char *dest, const unsigned char *src, uint32 src_length)
SECStatus SHA256_Hash (unsigned char *dest, const char *src)
void SHA256_TraceState (SHA256Context *ctx)
unsigned int SHA256_FlattenSize (SHA256Context *ctx)
SECStatus SHA256_Flatten (SHA256Context *ctx, unsigned char *space)
SHA256Context * SHA256_Resurrect (unsigned char *space, void *arg)
void SHA256_Clone (SHA256Context *dest, SHA256Context *src)
SHA512Context * SHA512_NewContext (void)
void SHA512_DestroyContext (SHA512Context *ctx, PRBool freeit)
void SHA512_Begin (SHA512Context *ctx)
static void SHA512_Compress (SHA512Context *ctx)
void SHA512_Update (SHA512Context *ctx, const unsigned char *input, unsigned int inputLen)
void SHA512_End (SHA512Context *ctx, unsigned char *digest, unsigned int *digestLen, unsigned int maxDigestLen)
SECStatus SHA512_HashBuf (unsigned char *dest, const unsigned char *src, uint32 src_length)
SECStatus SHA512_Hash (unsigned char *dest, const char *src)
void SHA512_TraceState (SHA512Context *ctx)
unsigned int SHA512_FlattenSize (SHA512Context *ctx)
SECStatus SHA512_Flatten (SHA512Context *ctx, unsigned char *space)
SHA512Context * SHA512_Resurrect (unsigned char *space, void *arg)
void SHA512_Clone (SHA512Context *dest, SHA512Context *src)
SHA384Context * SHA384_NewContext (void)
void SHA384_DestroyContext (SHA384Context *ctx, PRBool freeit)
void SHA384_Begin (SHA384Context *ctx)
void SHA384_Update (SHA384Context *ctx, const unsigned char *input, unsigned int inputLen)
void SHA384_End (SHA384Context *ctx, unsigned char *digest, unsigned int *digestLen, unsigned int maxDigestLen)
SECStatus SHA384_HashBuf (unsigned char *dest, const unsigned char *src, uint32 src_length)
SECStatus SHA384_Hash (unsigned char *dest, const char *src)
void SHA384_TraceState (SHA384Context *ctx)
unsigned int SHA384_FlattenSize (SHA384Context *ctx)
SECStatus SHA384_Flatten (SHA384Context *ctx, unsigned char *space)
SHA384Context * SHA384_Resurrect (unsigned char *space, void *arg)
void SHA384_Clone (SHA384Context *dest, SHA384Context *src)

Variables

static const PRUint8 pad [240]
static const PRUint32 K256 [64]
static const PRUint32 H256 [8]
static const PRUint64 K512 [80]
static const PRUint64 H512 [8]
static const PRUint64 H384 [8]

Class Documentation

struct SHA512ContextStr

Definition at line 645 of file sha512.c.

Collaboration diagram for SHA512ContextStr:
Class Members
PRUint64 h
PRUint64 sizeLo
union SHA512ContextStr u
union SHA512ContextStr u
union SHA512ContextStr.u

Definition at line 646 of file sha512.c.

Class Members
PRUint8 b
PRUint32 l
PRUint64 w

Define Documentation

#define ADDTO (   x,
  y 
)    y.lo += x.lo; y.hi += x.hi + (x.lo > y.lo)

Definition at line 724 of file sha512.c.

#define B   ctx->u.b

Definition at line 53 of file sha512.c.

#define BYTESWAP4 (   x)    x = SHA_HTONL(x)

Definition at line 131 of file sha512.c.

#define BYTESWAP8 (   x)
Value:
do { PRUint32 tmp; BYTESWAP4(x.lo); BYTESWAP4(x.hi); \
   tmp = x.lo; x.lo = x.hi; x.hi = tmp; } while (0)

Definition at line 554 of file sha512.c.

#define Ch (   x,
  y,
 
)    ((x & y) ^ (~x & z))

Definition at line 58 of file sha512.c.

#define Chxx (   x,
  y,
  z,
  lo 
)    ((x.lo & y.lo) ^ (~x.lo & z.lo))

Definition at line 744 of file sha512.c.

#define DUMP (   n,
  a,
  d,
  e,
 
)

Definition at line 704 of file sha512.c.

#define H   ctx->h

Definition at line 54 of file sha512.c.

#define INITW (   t)    W[t] = (s1(W[t-2]) + W[t-7] + s0(W[t-15]) + W[t-16])

Definition at line 747 of file sha512.c.

#define INITW (   t)
Value:
do { \
	PRUint32 lo, tm; \
	PRUint32 cy = 0; \
       lo = s1lo(W[t-2]); \
       lo += (tm = W[t-7].lo);     if (lo < tm) cy++; \
       lo += (tm = s0lo(W[t-15])); if (lo < tm) cy++; \
       lo += (tm = W[t-16].lo);    if (lo < tm) cy++; \
       W[t].lo = lo; \
       W[t].hi = cy + s1hi(W[t-2]) + W[t-7].hi + s0hi(W[t-15]) + W[t-16].hi; \
    } while (0)

Definition at line 747 of file sha512.c.

#define Maj (   x,
  y,
 
)    ((x & y) ^ (x & z) ^ (y & z))

Definition at line 59 of file sha512.c.

#define Majx (   x,
  y,
  z,
  lo 
)    ((x.lo & y.lo) ^ (x.lo & z.lo) ^ (y.lo & z.lo))

Definition at line 745 of file sha512.c.

Definition at line 722 of file sha512.c.

#define ROTL32 (   x,
  n 
)    ((x << n) | (x >> ((8 * sizeof x) - n)))

Definition at line 140 of file sha512.c.

#define ROTR32 (   x,
  n 
)    ((x >> n) | (x << ((8 * sizeof x) - n)))

Definition at line 139 of file sha512.c.

#define ROTR64a (   x,
  n,
  lo,
  hi 
)    (x.lo >> n | x.hi << (32-n))

Definition at line 726 of file sha512.c.

#define ROTR64A (   x,
  n,
  lo,
  hi 
)    (x.lo << (64-n) | x.hi >> (n-32))

Definition at line 727 of file sha512.c.

#define ROUND (   n,
  a,
  b,
  c,
  d,
  e,
  f,
  g,
 
)
Value:
h += S1(e) + Ch(e,f,g) + K256[n] + W[n]; \
    d += h; \
    h += S0(a) + Maj(a,b,c);

Definition at line 759 of file sha512.c.

#define ROUND (   n,
  a,
  b,
  c,
  d,
  e,
  f,
  g,
 
)
Value:
{ \
	PRUint32 lo, tm, cy; \
       lo  = S1lo(e); \
       lo += (tm = Chxx(e,f,g,lo));    cy = (lo < tm); \
       lo += (tm = K512[n].lo);    if (lo < tm) cy++; \
       lo += (tm =    W[n].lo);    if (lo < tm) cy++; \
       h.lo += lo;                 if (h.lo < lo) cy++; \
       h.hi += cy + S1hi(e) + Chxx(e,f,g,hi) + K512[n].hi + W[n].hi; \
       d.lo += h.lo; \
       d.hi += h.hi + (d.lo < h.lo); \
       lo  = S0lo(a);  \
       lo += (tm = Majx(a,b,c,lo));       cy = (lo < tm); \
       h.lo += lo;                 if (h.lo < lo) cy++; \
       h.hi += cy + S0hi(a) + Majx(a,b,c,hi); \
       DUMP(n,a,d,e,h) \
    }

Definition at line 759 of file sha512.c.

#define S0 (   x)    (ROTR32(x, 2) ^ ROTR32(x,13) ^ ROTR32(x,22))

Definition at line 144 of file sha512.c.

#define s0 (   x)    (t1 = x, ROTR32(t1, 7) ^ ROTR32(t1,18) ^ SHR(t1, 3))

Definition at line 146 of file sha512.c.

#define s0hi (   x)    (ROTR64a(x,1,hi,lo) ^ ROTR64a(x,8,hi,lo) ^ (x.hi >> 7))

Definition at line 732 of file sha512.c.

#define S0hi (   x)    (ROTR64a(x,28,hi,lo) ^ ROTR64A(x,34,hi,lo) ^ ROTR64A(x,39,hi,lo))

Definition at line 738 of file sha512.c.

#define s0lo (   x)    (ROTR64a(x,1,lo,hi) ^ ROTR64a(x,8,lo,hi) ^ SHR64a(x,7,lo,hi))

Definition at line 731 of file sha512.c.

#define S0lo (   x)    (ROTR64a(x,28,lo,hi) ^ ROTR64A(x,34,lo,hi) ^ ROTR64A(x,39,lo,hi))

Definition at line 737 of file sha512.c.

#define S1 (   x)    (ROTR32(x, 6) ^ ROTR32(x,11) ^ ROTR32(x,25))

Definition at line 145 of file sha512.c.

#define s1 (   x)    (t2 = x, ROTR32(t2,17) ^ ROTR32(t2,19) ^ SHR(t2,10))

Definition at line 147 of file sha512.c.

#define s1hi (   x)    (ROTR64a(x,19,hi,lo) ^ ROTR64A(x,61,hi,lo) ^ (x.hi >> 6))

Definition at line 735 of file sha512.c.

#define S1hi (   x)    (ROTR64a(x,14,hi,lo) ^ ROTR64a(x,18,hi,lo) ^ ROTR64A(x,41,hi,lo))

Definition at line 741 of file sha512.c.

#define s1lo (   x)    (ROTR64a(x,19,lo,hi) ^ ROTR64A(x,61,lo,hi) ^ SHR64a(x,6,lo,hi))

Definition at line 734 of file sha512.c.

#define S1lo (   x)    (ROTR64a(x,14,lo,hi) ^ ROTR64a(x,18,lo,hi) ^ ROTR64A(x,41,lo,hi))

Definition at line 740 of file sha512.c.

#define SHA_HTONL (   x)
Value:
(t1 = (x), t1 = (t1 << 16) | (t1 >> 16), \
                      ((t1 & SWAP4MASK) << 8) | ((t1 >> 8) & SWAP4MASK))

Definition at line 129 of file sha512.c.

Value:
( BYTESWAP4(x.lo), BYTESWAP4(x.hi), \
   x.hi ^= x.lo ^= x.hi ^= x.lo, x)

Definition at line 552 of file sha512.c.

#define SHA_MIN (   a,
  b 
)    (a < b ? a : b)
#define SHL (   x,
  n 
)    (x << n)

Definition at line 57 of file sha512.c.

#define SHR (   x,
  n 
)    (x >> n)

Definition at line 56 of file sha512.c.

#define SHR64a (   x,
  n,
  lo,
  hi 
)    (x.lo >> n | x.hi << (32-n))

Definition at line 728 of file sha512.c.

#define SWAP4MASK   0x00FF00FF

Definition at line 128 of file sha512.c.

#define ULLC (   hi,
  lo 
)    { 0x ## hi ## U, 0x ## lo ## U }

Definition at line 549 of file sha512.c.

#define W   ctx->u.w

Definition at line 52 of file sha512.c.


Function Documentation

void SHA256_Begin ( SHA256Context *  ctx)

Definition at line 165 of file sha512.c.

{
    memset(ctx, 0, sizeof *ctx);
    memcpy(H, H256, sizeof H256);
}

Here is the call graph for this function:

void SHA256_Clone ( SHA256Context *  dest,
SHA256Context *  src 
)

Definition at line 510 of file sha512.c.

{
    memcpy(dest, src, sizeof *dest);
}

Here is the call graph for this function:

static void SHA256_Compress ( SHA256Context *  ctx) [static]

Definition at line 172 of file sha512.c.

{
  {
    register PRUint32 t1, t2;

#if defined(IS_LITTLE_ENDIAN)
    BYTESWAP4(W[0]);
    BYTESWAP4(W[1]);
    BYTESWAP4(W[2]);
    BYTESWAP4(W[3]);
    BYTESWAP4(W[4]);
    BYTESWAP4(W[5]);
    BYTESWAP4(W[6]);
    BYTESWAP4(W[7]);
    BYTESWAP4(W[8]);
    BYTESWAP4(W[9]);
    BYTESWAP4(W[10]);
    BYTESWAP4(W[11]);
    BYTESWAP4(W[12]);
    BYTESWAP4(W[13]);
    BYTESWAP4(W[14]);
    BYTESWAP4(W[15]);
#endif

#define INITW(t) W[t] = (s1(W[t-2]) + W[t-7] + s0(W[t-15]) + W[t-16])

    /* prepare the "message schedule"   */
#ifdef NOUNROLL256
    {
       int t;
       for (t = 16; t < 64; ++t) {
           INITW(t);
       }
    }
#else
    INITW(16);
    INITW(17);
    INITW(18);
    INITW(19);

    INITW(20);
    INITW(21);
    INITW(22);
    INITW(23);
    INITW(24);
    INITW(25);
    INITW(26);
    INITW(27);
    INITW(28);
    INITW(29);

    INITW(30);
    INITW(31);
    INITW(32);
    INITW(33);
    INITW(34);
    INITW(35);
    INITW(36);
    INITW(37);
    INITW(38);
    INITW(39);

    INITW(40);
    INITW(41);
    INITW(42);
    INITW(43);
    INITW(44);
    INITW(45);
    INITW(46);
    INITW(47);
    INITW(48);
    INITW(49);

    INITW(50);
    INITW(51);
    INITW(52);
    INITW(53);
    INITW(54);
    INITW(55);
    INITW(56);
    INITW(57);
    INITW(58);
    INITW(59);

    INITW(60);
    INITW(61);
    INITW(62);
    INITW(63);

#endif
#undef INITW
  }
  {
    PRUint32 a, b, c, d, e, f, g, h;

    a = H[0];
    b = H[1];
    c = H[2];
    d = H[3];
    e = H[4];
    f = H[5];
    g = H[6];
    h = H[7];

#define ROUND(n,a,b,c,d,e,f,g,h) \
    h += S1(e) + Ch(e,f,g) + K256[n] + W[n]; \
    d += h; \
    h += S0(a) + Maj(a,b,c); 

#ifdef NOUNROLL256
    {
       int t;
       for (t = 0; t < 64; t+= 8) {
           ROUND(t+0,a,b,c,d,e,f,g,h)
           ROUND(t+1,h,a,b,c,d,e,f,g)
           ROUND(t+2,g,h,a,b,c,d,e,f)
           ROUND(t+3,f,g,h,a,b,c,d,e)
           ROUND(t+4,e,f,g,h,a,b,c,d)
           ROUND(t+5,d,e,f,g,h,a,b,c)
           ROUND(t+6,c,d,e,f,g,h,a,b)
           ROUND(t+7,b,c,d,e,f,g,h,a)
       }
    }
#else
    ROUND( 0,a,b,c,d,e,f,g,h)
    ROUND( 1,h,a,b,c,d,e,f,g)
    ROUND( 2,g,h,a,b,c,d,e,f)
    ROUND( 3,f,g,h,a,b,c,d,e)
    ROUND( 4,e,f,g,h,a,b,c,d)
    ROUND( 5,d,e,f,g,h,a,b,c)
    ROUND( 6,c,d,e,f,g,h,a,b)
    ROUND( 7,b,c,d,e,f,g,h,a)

    ROUND( 8,a,b,c,d,e,f,g,h)
    ROUND( 9,h,a,b,c,d,e,f,g)
    ROUND(10,g,h,a,b,c,d,e,f)
    ROUND(11,f,g,h,a,b,c,d,e)
    ROUND(12,e,f,g,h,a,b,c,d)
    ROUND(13,d,e,f,g,h,a,b,c)
    ROUND(14,c,d,e,f,g,h,a,b)
    ROUND(15,b,c,d,e,f,g,h,a)

    ROUND(16,a,b,c,d,e,f,g,h)
    ROUND(17,h,a,b,c,d,e,f,g)
    ROUND(18,g,h,a,b,c,d,e,f)
    ROUND(19,f,g,h,a,b,c,d,e)
    ROUND(20,e,f,g,h,a,b,c,d)
    ROUND(21,d,e,f,g,h,a,b,c)
    ROUND(22,c,d,e,f,g,h,a,b)
    ROUND(23,b,c,d,e,f,g,h,a)

    ROUND(24,a,b,c,d,e,f,g,h)
    ROUND(25,h,a,b,c,d,e,f,g)
    ROUND(26,g,h,a,b,c,d,e,f)
    ROUND(27,f,g,h,a,b,c,d,e)
    ROUND(28,e,f,g,h,a,b,c,d)
    ROUND(29,d,e,f,g,h,a,b,c)
    ROUND(30,c,d,e,f,g,h,a,b)
    ROUND(31,b,c,d,e,f,g,h,a)

    ROUND(32,a,b,c,d,e,f,g,h)
    ROUND(33,h,a,b,c,d,e,f,g)
    ROUND(34,g,h,a,b,c,d,e,f)
    ROUND(35,f,g,h,a,b,c,d,e)
    ROUND(36,e,f,g,h,a,b,c,d)
    ROUND(37,d,e,f,g,h,a,b,c)
    ROUND(38,c,d,e,f,g,h,a,b)
    ROUND(39,b,c,d,e,f,g,h,a)

    ROUND(40,a,b,c,d,e,f,g,h)
    ROUND(41,h,a,b,c,d,e,f,g)
    ROUND(42,g,h,a,b,c,d,e,f)
    ROUND(43,f,g,h,a,b,c,d,e)
    ROUND(44,e,f,g,h,a,b,c,d)
    ROUND(45,d,e,f,g,h,a,b,c)
    ROUND(46,c,d,e,f,g,h,a,b)
    ROUND(47,b,c,d,e,f,g,h,a)

    ROUND(48,a,b,c,d,e,f,g,h)
    ROUND(49,h,a,b,c,d,e,f,g)
    ROUND(50,g,h,a,b,c,d,e,f)
    ROUND(51,f,g,h,a,b,c,d,e)
    ROUND(52,e,f,g,h,a,b,c,d)
    ROUND(53,d,e,f,g,h,a,b,c)
    ROUND(54,c,d,e,f,g,h,a,b)
    ROUND(55,b,c,d,e,f,g,h,a)

    ROUND(56,a,b,c,d,e,f,g,h)
    ROUND(57,h,a,b,c,d,e,f,g)
    ROUND(58,g,h,a,b,c,d,e,f)
    ROUND(59,f,g,h,a,b,c,d,e)
    ROUND(60,e,f,g,h,a,b,c,d)
    ROUND(61,d,e,f,g,h,a,b,c)
    ROUND(62,c,d,e,f,g,h,a,b)
    ROUND(63,b,c,d,e,f,g,h,a)
#endif

    H[0] += a;
    H[1] += b;
    H[2] += c;
    H[3] += d;
    H[4] += e;
    H[5] += f;
    H[6] += g;
    H[7] += h;
  }
#undef ROUND
}

Here is the caller graph for this function:

void SHA256_DestroyContext ( SHA256Context *  ctx,
PRBool  freeit 
)

Definition at line 157 of file sha512.c.

{
    if (freeit) {
        PORT_ZFree(ctx, sizeof *ctx);
    }
}

Here is the call graph for this function:

void SHA256_End ( SHA256Context *  ctx,
unsigned char *  digest,
unsigned int digestLen,
unsigned int  maxDigestLen 
)

Definition at line 423 of file sha512.c.

{
    unsigned int inBuf = ctx->sizeLo & 0x3f;
    unsigned int padLen = (inBuf < 56) ? (56 - inBuf) : (56 + 64 - inBuf);
    PRUint32 hi, lo;
#ifdef SWAP4MASK
    PRUint32 t1;
#endif

    hi = (ctx->sizeHi << 3) | (ctx->sizeLo >> 29);
    lo = (ctx->sizeLo << 3);

    SHA256_Update(ctx, pad, padLen);

#if defined(IS_LITTLE_ENDIAN)
    W[14] = SHA_HTONL(hi);
    W[15] = SHA_HTONL(lo);
#else
    W[14] = hi;
    W[15] = lo;
#endif
    SHA256_Compress(ctx);

    /* now output the answer */
#if defined(IS_LITTLE_ENDIAN)
    BYTESWAP4(H[0]);
    BYTESWAP4(H[1]);
    BYTESWAP4(H[2]);
    BYTESWAP4(H[3]);
    BYTESWAP4(H[4]);
    BYTESWAP4(H[5]);
    BYTESWAP4(H[6]);
    BYTESWAP4(H[7]);
#endif
    padLen = PR_MIN(SHA256_LENGTH, maxDigestLen);
    memcpy(digest, H, padLen);
    if (digestLen)
       *digestLen = padLen;
}

Here is the call graph for this function:

SECStatus SHA256_Flatten ( SHA256Context *  ctx,
unsigned char *  space 
)

Definition at line 495 of file sha512.c.

{
    PORT_Memcpy(space, ctx, sizeof *ctx);
    return SECSuccess;
}
unsigned int SHA256_FlattenSize ( SHA256Context *  ctx)

Definition at line 489 of file sha512.c.

{
    return sizeof *ctx;
}
SECStatus SHA256_Hash ( unsigned char *  dest,
const char *  src 
)

Definition at line 480 of file sha512.c.

{
    return SHA256_HashBuf(dest, (const unsigned char *)src, PORT_Strlen(src));
}

Here is the call graph for this function:

SECStatus SHA256_HashBuf ( unsigned char *  dest,
const unsigned char *  src,
uint32  src_length 
)

Definition at line 465 of file sha512.c.

{
    SHA256Context ctx;
    unsigned int outLen;

    SHA256_Begin(&ctx);
    SHA256_Update(&ctx, src, src_length);
    SHA256_End(&ctx, dest, &outLen, SHA256_LENGTH);

    return SECSuccess;
}

Here is the call graph for this function:

SHA256Context* SHA256_NewContext ( void  )

Definition at line 150 of file sha512.c.

{
    SHA256Context *ctx = PORT_New(SHA256Context);
    return ctx;
}
SHA256Context* SHA256_Resurrect ( unsigned char *  space,
void arg 
)

Definition at line 502 of file sha512.c.

{
    SHA256Context *ctx = SHA256_NewContext();
    if (ctx) 
       PORT_Memcpy(ctx, space, sizeof *ctx);
    return ctx;
}

Here is the call graph for this function:

void SHA256_TraceState ( SHA256Context *  ctx)

Definition at line 486 of file sha512.c.

{ }
void SHA256_Update ( SHA256Context *  ctx,
const unsigned char *  input,
unsigned int  inputLen 
)

Definition at line 387 of file sha512.c.

{
    unsigned int inBuf = ctx->sizeLo & 0x3f;
    if (!inputLen)
       return;

    /* Add inputLen into the count of bytes processed, before processing */
    if ((ctx->sizeLo += inputLen) < inputLen)
       ctx->sizeHi++;

    /* if data already in buffer, attemp to fill rest of buffer */
    if (inBuf) {
       unsigned int todo = SHA256_BLOCK_LENGTH - inBuf;
       if (inputLen < todo)
           todo = inputLen;
       memcpy(B + inBuf, input, todo);
       input    += todo;
       inputLen -= todo;
       if (inBuf + todo == SHA256_BLOCK_LENGTH)
           SHA256_Compress(ctx);
    }

    /* if enough data to fill one or more whole buffers, process them. */
    while (inputLen >= SHA256_BLOCK_LENGTH) {
       memcpy(B, input, SHA256_BLOCK_LENGTH);
       input    += SHA256_BLOCK_LENGTH;
       inputLen -= SHA256_BLOCK_LENGTH;
       SHA256_Compress(ctx);
    }
    /* if data left over, fill it into buffer */
    if (inputLen) 
       memcpy(B, input, inputLen);
}

Here is the call graph for this function:

void SHA384_Begin ( SHA384Context *  ctx)

Definition at line 1208 of file sha512.c.

{
    memset(ctx, 0, sizeof *ctx);
    memcpy(H, H384, sizeof H384);
}

Here is the call graph for this function:

void SHA384_Clone ( SHA384Context *  dest,
SHA384Context *  src 
)

Definition at line 1270 of file sha512.c.

{
    memcpy(dest, src, sizeof *dest);
}

Here is the call graph for this function:

void SHA384_DestroyContext ( SHA384Context *  ctx,
PRBool  freeit 
)

Definition at line 1202 of file sha512.c.

Here is the call graph for this function:

void SHA384_End ( SHA384Context *  ctx,
unsigned char *  digest,
unsigned int digestLen,
unsigned int  maxDigestLen 
)

Definition at line 1222 of file sha512.c.

{
#define SHA_MIN(a,b) (a < b ? a : b)
    unsigned int maxLen = SHA_MIN(maxDigestLen, SHA384_LENGTH);
    SHA512_End(ctx, digest, digestLen, maxLen);
}

Here is the call graph for this function:

SECStatus SHA384_Flatten ( SHA384Context *  ctx,
unsigned char *  space 
)

Definition at line 1259 of file sha512.c.

{
    return SHA512_Flatten(ctx, space);
}

Here is the call graph for this function:

unsigned int SHA384_FlattenSize ( SHA384Context *  ctx)

Definition at line 1253 of file sha512.c.

{
    return sizeof(SHA384Context);
}
SECStatus SHA384_Hash ( unsigned char *  dest,
const char *  src 
)

Definition at line 1245 of file sha512.c.

{
    return SHA384_HashBuf(dest, (const unsigned char *)src, PORT_Strlen(src));
}

Here is the call graph for this function:

SECStatus SHA384_HashBuf ( unsigned char *  dest,
const unsigned char *  src,
uint32  src_length 
)

Definition at line 1231 of file sha512.c.

{
    SHA512Context ctx;
    unsigned int outLen;

    SHA384_Begin(&ctx);
    SHA512_Update(&ctx, src, src_length);
    SHA512_End(&ctx, dest, &outLen, SHA384_LENGTH);

    return SECSuccess;
}

Here is the call graph for this function:

SHA384Context* SHA384_NewContext ( void  )

Definition at line 1196 of file sha512.c.

{
    return SHA512_NewContext();
}

Here is the call graph for this function:

SHA384Context* SHA384_Resurrect ( unsigned char *  space,
void arg 
)

Definition at line 1265 of file sha512.c.

{
    return SHA512_Resurrect(space, arg);
}

Here is the call graph for this function:

void SHA384_TraceState ( SHA384Context *  ctx)

Definition at line 1250 of file sha512.c.

{ }
void SHA384_Update ( SHA384Context *  ctx,
const unsigned char *  input,
unsigned int  inputLen 
)

Definition at line 1215 of file sha512.c.

{
    SHA512_Update(ctx, input, inputLen);
}

Here is the call graph for this function:

void SHA512_Begin ( SHA512Context *  ctx)

Definition at line 689 of file sha512.c.

{
    memset(ctx, 0, sizeof *ctx);
    memcpy(H, H512, sizeof H512);
}

Here is the call graph for this function:

void SHA512_Clone ( SHA512Context *  dest,
SHA512Context *  src 
)

Definition at line 1168 of file sha512.c.

{
    memcpy(dest, src, sizeof *dest);
}

Here is the call graph for this function:

static void SHA512_Compress ( SHA512Context *  ctx) [static]

Definition at line 779 of file sha512.c.

{
#if defined(IS_LITTLE_ENDIAN)
  {
#if defined(HAVE_LONG_LONG)
    PRUint64 t1;
#else
    PRUint32 t1;
#endif
    BYTESWAP8(W[0]);
    BYTESWAP8(W[1]);
    BYTESWAP8(W[2]);
    BYTESWAP8(W[3]);
    BYTESWAP8(W[4]);
    BYTESWAP8(W[5]);
    BYTESWAP8(W[6]);
    BYTESWAP8(W[7]);
    BYTESWAP8(W[8]);
    BYTESWAP8(W[9]);
    BYTESWAP8(W[10]);
    BYTESWAP8(W[11]);
    BYTESWAP8(W[12]);
    BYTESWAP8(W[13]);
    BYTESWAP8(W[14]);
    BYTESWAP8(W[15]);
  }
#endif

  {
    PRUint64 t1, t2;
#ifdef NOUNROLL512
    {
       /* prepare the "message schedule"   */
       int t;
       for (t = 16; t < 80; ++t) {
           INITW(t);
       }
    }
#else
    INITW(16);
    INITW(17);
    INITW(18);
    INITW(19);

    INITW(20);
    INITW(21);
    INITW(22);
    INITW(23);
    INITW(24);
    INITW(25);
    INITW(26);
    INITW(27);
    INITW(28);
    INITW(29);

    INITW(30);
    INITW(31);
    INITW(32);
    INITW(33);
    INITW(34);
    INITW(35);
    INITW(36);
    INITW(37);
    INITW(38);
    INITW(39);

    INITW(40);
    INITW(41);
    INITW(42);
    INITW(43);
    INITW(44);
    INITW(45);
    INITW(46);
    INITW(47);
    INITW(48);
    INITW(49);

    INITW(50);
    INITW(51);
    INITW(52);
    INITW(53);
    INITW(54);
    INITW(55);
    INITW(56);
    INITW(57);
    INITW(58);
    INITW(59);

    INITW(60);
    INITW(61);
    INITW(62);
    INITW(63);
    INITW(64);
    INITW(65);
    INITW(66);
    INITW(67);
    INITW(68);
    INITW(69);

    INITW(70);
    INITW(71);
    INITW(72);
    INITW(73);
    INITW(74);
    INITW(75);
    INITW(76);
    INITW(77);
    INITW(78);
    INITW(79);
#endif
  }
#ifdef SHA512_TRACE
  {
    int i;
    for (i = 0; i < 80; ++i) {
#ifdef HAVE_LONG_LONG
       printf("W[%2d] = %016lx\n", i, W[i]);
#else
       printf("W[%2d] = %08x%08x\n", i, W[i].hi, W[i].lo);
#endif
    }
  }
#endif
  {
    PRUint64 a, b, c, d, e, f, g, h;

    a = H[0];
    b = H[1];
    c = H[2];
    d = H[3];
    e = H[4];
    f = H[5];
    g = H[6];
    h = H[7];

#ifdef NOUNROLL512
    {
       int t;
       for (t = 0; t < 80; t+= 8) {
           ROUND(t+0,a,b,c,d,e,f,g,h)
           ROUND(t+1,h,a,b,c,d,e,f,g)
           ROUND(t+2,g,h,a,b,c,d,e,f)
           ROUND(t+3,f,g,h,a,b,c,d,e)
           ROUND(t+4,e,f,g,h,a,b,c,d)
           ROUND(t+5,d,e,f,g,h,a,b,c)
           ROUND(t+6,c,d,e,f,g,h,a,b)
           ROUND(t+7,b,c,d,e,f,g,h,a)
       }
    }
#else
    ROUND( 0,a,b,c,d,e,f,g,h)
    ROUND( 1,h,a,b,c,d,e,f,g)
    ROUND( 2,g,h,a,b,c,d,e,f)
    ROUND( 3,f,g,h,a,b,c,d,e)
    ROUND( 4,e,f,g,h,a,b,c,d)
    ROUND( 5,d,e,f,g,h,a,b,c)
    ROUND( 6,c,d,e,f,g,h,a,b)
    ROUND( 7,b,c,d,e,f,g,h,a)

    ROUND( 8,a,b,c,d,e,f,g,h)
    ROUND( 9,h,a,b,c,d,e,f,g)
    ROUND(10,g,h,a,b,c,d,e,f)
    ROUND(11,f,g,h,a,b,c,d,e)
    ROUND(12,e,f,g,h,a,b,c,d)
    ROUND(13,d,e,f,g,h,a,b,c)
    ROUND(14,c,d,e,f,g,h,a,b)
    ROUND(15,b,c,d,e,f,g,h,a)

    ROUND(16,a,b,c,d,e,f,g,h)
    ROUND(17,h,a,b,c,d,e,f,g)
    ROUND(18,g,h,a,b,c,d,e,f)
    ROUND(19,f,g,h,a,b,c,d,e)
    ROUND(20,e,f,g,h,a,b,c,d)
    ROUND(21,d,e,f,g,h,a,b,c)
    ROUND(22,c,d,e,f,g,h,a,b)
    ROUND(23,b,c,d,e,f,g,h,a)

    ROUND(24,a,b,c,d,e,f,g,h)
    ROUND(25,h,a,b,c,d,e,f,g)
    ROUND(26,g,h,a,b,c,d,e,f)
    ROUND(27,f,g,h,a,b,c,d,e)
    ROUND(28,e,f,g,h,a,b,c,d)
    ROUND(29,d,e,f,g,h,a,b,c)
    ROUND(30,c,d,e,f,g,h,a,b)
    ROUND(31,b,c,d,e,f,g,h,a)

    ROUND(32,a,b,c,d,e,f,g,h)
    ROUND(33,h,a,b,c,d,e,f,g)
    ROUND(34,g,h,a,b,c,d,e,f)
    ROUND(35,f,g,h,a,b,c,d,e)
    ROUND(36,e,f,g,h,a,b,c,d)
    ROUND(37,d,e,f,g,h,a,b,c)
    ROUND(38,c,d,e,f,g,h,a,b)
    ROUND(39,b,c,d,e,f,g,h,a)

    ROUND(40,a,b,c,d,e,f,g,h)
    ROUND(41,h,a,b,c,d,e,f,g)
    ROUND(42,g,h,a,b,c,d,e,f)
    ROUND(43,f,g,h,a,b,c,d,e)
    ROUND(44,e,f,g,h,a,b,c,d)
    ROUND(45,d,e,f,g,h,a,b,c)
    ROUND(46,c,d,e,f,g,h,a,b)
    ROUND(47,b,c,d,e,f,g,h,a)

    ROUND(48,a,b,c,d,e,f,g,h)
    ROUND(49,h,a,b,c,d,e,f,g)
    ROUND(50,g,h,a,b,c,d,e,f)
    ROUND(51,f,g,h,a,b,c,d,e)
    ROUND(52,e,f,g,h,a,b,c,d)
    ROUND(53,d,e,f,g,h,a,b,c)
    ROUND(54,c,d,e,f,g,h,a,b)
    ROUND(55,b,c,d,e,f,g,h,a)

    ROUND(56,a,b,c,d,e,f,g,h)
    ROUND(57,h,a,b,c,d,e,f,g)
    ROUND(58,g,h,a,b,c,d,e,f)
    ROUND(59,f,g,h,a,b,c,d,e)
    ROUND(60,e,f,g,h,a,b,c,d)
    ROUND(61,d,e,f,g,h,a,b,c)
    ROUND(62,c,d,e,f,g,h,a,b)
    ROUND(63,b,c,d,e,f,g,h,a)

    ROUND(64,a,b,c,d,e,f,g,h)
    ROUND(65,h,a,b,c,d,e,f,g)
    ROUND(66,g,h,a,b,c,d,e,f)
    ROUND(67,f,g,h,a,b,c,d,e)
    ROUND(68,e,f,g,h,a,b,c,d)
    ROUND(69,d,e,f,g,h,a,b,c)
    ROUND(70,c,d,e,f,g,h,a,b)
    ROUND(71,b,c,d,e,f,g,h,a)

    ROUND(72,a,b,c,d,e,f,g,h)
    ROUND(73,h,a,b,c,d,e,f,g)
    ROUND(74,g,h,a,b,c,d,e,f)
    ROUND(75,f,g,h,a,b,c,d,e)
    ROUND(76,e,f,g,h,a,b,c,d)
    ROUND(77,d,e,f,g,h,a,b,c)
    ROUND(78,c,d,e,f,g,h,a,b)
    ROUND(79,b,c,d,e,f,g,h,a)
#endif

    ADDTO(a,H[0]);
    ADDTO(b,H[1]);
    ADDTO(c,H[2]);
    ADDTO(d,H[3]);
    ADDTO(e,H[4]);
    ADDTO(f,H[5]);
    ADDTO(g,H[6]);
    ADDTO(h,H[7]);
  }
}

Here is the caller graph for this function:

void SHA512_DestroyContext ( SHA512Context *  ctx,
PRBool  freeit 
)

Definition at line 681 of file sha512.c.

{
    if (freeit) {
        PORT_ZFree(ctx, sizeof *ctx);
    }
}

Here is the call graph for this function:

void SHA512_End ( SHA512Context *  ctx,
unsigned char *  digest,
unsigned int digestLen,
unsigned int  maxDigestLen 
)

Definition at line 1074 of file sha512.c.

{
#if defined(HAVE_LONG_LONG)
    unsigned int inBuf  = (unsigned int)ctx->sizeLo & 0x7f;
    unsigned int padLen = (inBuf < 112) ? (112 - inBuf) : (112 + 128 - inBuf);
    PRUint64 lo, t1;
    lo = (ctx->sizeLo << 3);
#else
    unsigned int inBuf  = (unsigned int)ctx->sizeLo.lo & 0x7f;
    unsigned int padLen = (inBuf < 112) ? (112 - inBuf) : (112 + 128 - inBuf);
    PRUint64 lo = ctx->sizeLo;
    PRUint32 t1;
    lo.lo <<= 3;
#endif

    SHA512_Update(ctx, pad, padLen);

#if defined(HAVE_LONG_LONG)
    W[14] = 0;
#else
    W[14].lo = 0;
    W[14].hi = 0;
#endif

    W[15] = lo;
#if defined(IS_LITTLE_ENDIAN)
    BYTESWAP8(W[15]);
#endif
    SHA512_Compress(ctx);

    /* now output the answer */
#if defined(IS_LITTLE_ENDIAN)
    BYTESWAP8(H[0]);
    BYTESWAP8(H[1]);
    BYTESWAP8(H[2]);
    BYTESWAP8(H[3]);
    BYTESWAP8(H[4]);
    BYTESWAP8(H[5]);
    BYTESWAP8(H[6]);
    BYTESWAP8(H[7]);
#endif
    padLen = PR_MIN(SHA512_LENGTH, maxDigestLen);
    memcpy(digest, H, padLen);
    if (digestLen)
       *digestLen = padLen;
}

Here is the call graph for this function:

SECStatus SHA512_Flatten ( SHA512Context *  ctx,
unsigned char *  space 
)

Definition at line 1153 of file sha512.c.

{
    PORT_Memcpy(space, ctx, sizeof *ctx);
    return SECSuccess;
}
unsigned int SHA512_FlattenSize ( SHA512Context *  ctx)

Definition at line 1147 of file sha512.c.

{
    return sizeof *ctx;
}
SECStatus SHA512_Hash ( unsigned char *  dest,
const char *  src 
)

Definition at line 1138 of file sha512.c.

{
    return SHA512_HashBuf(dest, (const unsigned char *)src, PORT_Strlen(src));
}

Here is the call graph for this function:

SECStatus SHA512_HashBuf ( unsigned char *  dest,
const unsigned char *  src,
uint32  src_length 
)

Definition at line 1123 of file sha512.c.

{
    SHA512Context ctx;
    unsigned int outLen;

    SHA512_Begin(&ctx);
    SHA512_Update(&ctx, src, src_length);
    SHA512_End(&ctx, dest, &outLen, SHA512_LENGTH);

    return SECSuccess;
}

Here is the call graph for this function:

SHA512Context* SHA512_NewContext ( void  )

Definition at line 674 of file sha512.c.

{
    SHA512Context *ctx = PORT_New(SHA512Context);
    return ctx;
}
SHA512Context* SHA512_Resurrect ( unsigned char *  space,
void arg 
)

Definition at line 1160 of file sha512.c.

{
    SHA512Context *ctx = SHA512_NewContext();
    if (ctx) 
       PORT_Memcpy(ctx, space, sizeof *ctx);
    return ctx;
}

Here is the call graph for this function:

void SHA512_TraceState ( SHA512Context *  ctx)

Definition at line 1144 of file sha512.c.

{ }
void SHA512_Update ( SHA512Context *  ctx,
const unsigned char *  input,
unsigned int  inputLen 
)

Definition at line 1032 of file sha512.c.

{
    unsigned int inBuf;
    if (!inputLen)
       return;

#if defined(HAVE_LONG_LONG)
    inBuf = (unsigned int)ctx->sizeLo & 0x7f;
    /* Add inputLen into the count of bytes processed, before processing */
    ctx->sizeLo += inputLen;
#else
    inBuf = (unsigned int)ctx->sizeLo.lo & 0x7f;
    ctx->sizeLo.lo += inputLen;
    if (ctx->sizeLo.lo < inputLen) ctx->sizeLo.hi++;
#endif

    /* if data already in buffer, attemp to fill rest of buffer */
    if (inBuf) {
       unsigned int todo = SHA512_BLOCK_LENGTH - inBuf;
       if (inputLen < todo)
           todo = inputLen;
       memcpy(B + inBuf, input, todo);
       input    += todo;
       inputLen -= todo;
       if (inBuf + todo == SHA512_BLOCK_LENGTH)
           SHA512_Compress(ctx);
    }

    /* if enough data to fill one or more whole buffers, process them. */
    while (inputLen >= SHA512_BLOCK_LENGTH) {
       memcpy(B, input, SHA512_BLOCK_LENGTH);
       input    += SHA512_BLOCK_LENGTH;
       inputLen -= SHA512_BLOCK_LENGTH;
       SHA512_Compress(ctx);
    }
    /* if data left over, fill it into buffer */
    if (inputLen) 
       memcpy(B, input, inputLen);
}

Here is the call graph for this function:


Variable Documentation

const PRUint32 H256[8] [static]
Initial value:
 {
    0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 
    0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
}

Definition at line 91 of file sha512.c.

const PRUint64 H384[8] [static]
Initial value:
 {






    ULLC(cbbb9d5d,c1059ed8), ULLC(629a292a,367cd507), 
    ULLC(9159015a,3070dd17), ULLC(152fecd8,f70e5939), 
    ULLC(67332667,ffc00b31), ULLC(8eb44a87,68581511), 
    ULLC(db0c2e0d,64f98fa7), ULLC(47b5481d,befa4fa4)

}

Definition at line 1181 of file sha512.c.

const PRUint64 H512[8] [static]
Initial value:
 {






    ULLC(6a09e667,f3bcc908), ULLC(bb67ae85,84caa73b), 
    ULLC(3c6ef372,fe94f82b), ULLC(a54ff53a,5f1d36f1), 
    ULLC(510e527f,ade682d1), ULLC(9b05688c,2b3e6c1f), 
    ULLC(1f83d9ab,fb41bd6b), ULLC(5be0cd19,137e2179)

}

Definition at line 658 of file sha512.c.

const PRUint32 K256[64] [static]
Initial value:
 {
    0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 
    0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
    0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 
    0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
    0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 
    0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
    0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 
    0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
    0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 
    0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
    0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 
    0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
    0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 
    0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
    0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 
    0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
}

Definition at line 71 of file sha512.c.

const PRUint64 K512[80] [static]

Definition at line 559 of file sha512.c.

const PRUint8 pad[240] [static]
Initial value:
 { 
0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   
}

Definition at line 62 of file sha512.c.