0000: 2f 2a 20 73 68 61 35 31 32 2e 63 20 2d 20 61 6e /* sha512.c - an
0010: 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 implementation
0020: 6f 66 20 53 48 41 2d 33 38 34 2f 35 31 32 20 68 of SHA-384/512 h
0030: 61 73 68 20 66 75 6e 63 74 69 6f 6e 73 0a 20 2a ash functions. *
0040: 20 62 61 73 65 64 20 6f 6e 20 46 49 50 53 20 31 based on FIPS 1
0050: 38 30 2d 33 20 28 46 65 64 65 72 61 6c 20 49 6e 80-3 (Federal In
0060: 66 6f 72 6d 61 74 69 6f 6e 20 50 72 6f 63 65 73 formation Proces
0070: 73 69 6e 67 20 53 74 61 6e 64 61 72 74 29 2e 0a sing Standart)..
0080: 20 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 3a *. * Copyright:
0090: 20 32 30 31 30 2d 32 30 31 32 20 41 6c 65 6b 73 2010-2012 Aleks
00a0: 65 79 20 4b 72 61 76 63 68 65 6e 6b 6f 20 3c 72 ey Kravchenko <r
00b0: 68 61 73 68 2e 61 64 6d 69 6e 40 67 6d 61 69 6c hash.admin@gmail
00c0: 2e 63 6f 6d 3e 0a 20 2a 0a 20 2a 20 50 65 72 6d .com>. *. * Perm
00d0: 69 73 73 69 6f 6e 20 69 73 20 68 65 72 65 62 79 ission is hereby
00e0: 20 67 72 61 6e 74 65 64 2c 20 20 66 72 65 65 20 granted, free
00f0: 6f 66 20 63 68 61 72 67 65 2c 20 20 74 6f 20 61 of charge, to a
0100: 6e 79 20 70 65 72 73 6f 6e 20 20 6f 62 74 61 69 ny person obtai
0110: 6e 69 6e 67 20 61 0a 20 2a 20 63 6f 70 79 20 6f ning a. * copy o
0120: 66 20 74 68 69 73 20 73 6f 66 74 77 61 72 65 20 f this software
0130: 61 6e 64 20 61 73 73 6f 63 69 61 74 65 64 20 64 and associated d
0140: 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 20 66 69 6c ocumentation fil
0150: 65 73 20 28 74 68 65 20 22 53 6f 66 74 77 61 72 es (the "Softwar
0160: 65 22 29 2c 0a 20 2a 20 74 6f 20 64 65 61 6c 20 e"),. * to deal
0170: 69 6e 20 74 68 65 20 53 6f 66 74 77 61 72 65 20 in the Software
0180: 77 69 74 68 6f 75 74 20 72 65 73 74 72 69 63 74 without restrict
0190: 69 6f 6e 2c 20 20 69 6e 63 6c 75 64 69 6e 67 20 ion, including
01a0: 77 69 74 68 6f 75 74 20 6c 69 6d 69 74 61 74 69 without limitati
01b0: 6f 6e 0a 20 2a 20 74 68 65 20 72 69 67 68 74 73 on. * the rights
01c0: 20 74 6f 20 20 75 73 65 2c 20 63 6f 70 79 2c 20 to use, copy,
01d0: 6d 6f 64 69 66 79 2c 20 20 6d 65 72 67 65 2c 20 modify, merge,
01e0: 70 75 62 6c 69 73 68 2c 20 64 69 73 74 72 69 62 publish, distrib
01f0: 75 74 65 2c 20 73 75 62 6c 69 63 65 6e 73 65 2c ute, sublicense,
0200: 0a 20 2a 20 61 6e 64 2f 6f 72 20 73 65 6c 6c 20 . * and/or sell
0210: 63 6f 70 69 65 73 20 20 6f 66 20 20 74 68 65 20 copies of the
0220: 53 6f 66 74 77 61 72 65 2c 20 20 61 6e 64 20 74 Software, and t
0230: 6f 20 70 65 72 6d 69 74 20 20 70 65 72 73 6f 6e o permit person
0240: 73 20 20 74 6f 20 77 68 6f 6d 20 74 68 65 0a 20 s to whom the.
0250: 2a 20 53 6f 66 74 77 61 72 65 20 69 73 20 66 75 * Software is fu
0260: 72 6e 69 73 68 65 64 20 74 6f 20 64 6f 20 73 6f rnished to do so
0270: 2e 0a 20 2a 0a 20 2a 20 54 68 69 73 20 70 72 6f .. *. * This pro
0280: 67 72 61 6d 20 20 69 73 20 20 64 69 73 74 72 69 gram is distri
0290: 62 75 74 65 64 20 20 69 6e 20 20 74 68 65 20 20 buted in the
02a0: 68 6f 70 65 20 20 74 68 61 74 20 69 74 20 77 69 hope that it wi
02b0: 6c 6c 20 62 65 20 75 73 65 66 75 6c 2c 20 20 62 ll be useful, b
02c0: 75 74 0a 20 2a 20 57 49 54 48 4f 55 54 20 41 4e ut. * WITHOUT AN
02d0: 59 20 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 Y WARRANTY; with
02e0: 6f 75 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 out even the imp
02f0: 6c 69 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 lied warranty of
0300: 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54 59 MERCHANTABILITY
0310: 0a 20 2a 20 6f 72 20 46 49 54 4e 45 53 53 20 46 . * or FITNESS F
0320: 4f 52 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 OR A PARTICULAR
0330: 50 55 52 50 4f 53 45 2e 20 20 55 73 65 20 74 68 PURPOSE. Use th
0340: 69 73 20 70 72 6f 67 72 61 6d 20 20 61 74 20 20 is program at
0350: 79 6f 75 72 20 6f 77 6e 20 72 69 73 6b 21 0a 20 your own risk!.
0360: 2a 2f 0a 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 */..#include <st
0370: 72 69 6e 67 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 ring.h>.#include
0380: 20 22 62 79 74 65 5f 6f 72 64 65 72 2e 68 22 0a "byte_order.h".
0390: 23 69 6e 63 6c 75 64 65 20 22 73 68 61 35 31 32 #include "sha512
03a0: 2e 68 22 0a 0a 2f 2a 20 53 48 41 2d 33 38 34 20 .h"../* SHA-384
03b0: 61 6e 64 20 53 48 41 2d 35 31 32 20 63 6f 6e 73 and SHA-512 cons
03c0: 74 61 6e 74 73 20 66 6f 72 20 38 30 20 72 6f 75 tants for 80 rou
03d0: 6e 64 73 2e 20 54 68 65 73 65 20 71 77 6f 72 64 nds. These qword
03e0: 73 20 72 65 70 72 65 73 65 6e 74 0a 20 2a 20 74 s represent. * t
03f0: 68 65 20 66 69 72 73 74 20 36 34 20 62 69 74 73 he first 64 bits
0400: 20 6f 66 20 74 68 65 20 66 72 61 63 74 69 6f 6e of the fraction
0410: 61 6c 20 70 61 72 74 73 20 6f 66 20 74 68 65 20 al parts of the
0420: 63 75 62 65 0a 20 2a 20 72 6f 6f 74 73 20 6f 66 cube. * roots of
0430: 20 74 68 65 20 66 69 72 73 74 20 38 30 20 70 72 the first 80 pr
0440: 69 6d 65 20 6e 75 6d 62 65 72 73 2e 20 2a 2f 0a ime numbers. */.
0450: 73 74 61 74 69 63 20 63 6f 6e 73 74 20 75 69 6e static const uin
0460: 74 36 34 5f 74 20 72 68 61 73 68 5f 6b 35 31 32 t64_t rhash_k512
0470: 5b 38 30 5d 20 3d 20 7b 0a 09 49 36 34 28 30 78 [80] = {..I64(0x
0480: 34 32 38 61 32 66 39 38 64 37 32 38 61 65 32 32 428a2f98d728ae22
0490: 29 2c 20 49 36 34 28 30 78 37 31 33 37 34 34 39 ), I64(0x7137449
04a0: 31 32 33 65 66 36 35 63 64 29 2c 20 49 36 34 28 123ef65cd), I64(
04b0: 30 78 62 35 63 30 66 62 63 66 65 63 34 64 33 62 0xb5c0fbcfec4d3b
04c0: 32 66 29 2c 0a 09 49 36 34 28 30 78 65 39 62 35 2f),..I64(0xe9b5
04d0: 64 62 61 35 38 31 38 39 64 62 62 63 29 2c 20 49 dba58189dbbc), I
04e0: 36 34 28 30 78 33 39 35 36 63 32 35 62 66 33 34 64(0x3956c25bf34
04f0: 38 62 35 33 38 29 2c 20 49 36 34 28 30 78 35 39 8b538), I64(0x59
0500: 66 31 31 31 66 31 62 36 30 35 64 30 31 39 29 2c f111f1b605d019),
0510: 0a 09 49 36 34 28 30 78 39 32 33 66 38 32 61 34 ..I64(0x923f82a4
0520: 61 66 31 39 34 66 39 62 29 2c 20 49 36 34 28 30 af194f9b), I64(0
0530: 78 61 62 31 63 35 65 64 35 64 61 36 64 38 31 31 xab1c5ed5da6d811
0540: 38 29 2c 20 49 36 34 28 30 78 64 38 30 37 61 61 8), I64(0xd807aa
0550: 39 38 61 33 30 33 30 32 34 32 29 2c 0a 09 49 36 98a3030242),..I6
0560: 34 28 30 78 31 32 38 33 35 62 30 31 34 35 37 30 4(0x12835b014570
0570: 36 66 62 65 29 2c 20 49 36 34 28 30 78 32 34 33 6fbe), I64(0x243
0580: 31 38 35 62 65 34 65 65 34 62 32 38 63 29 2c 20 185be4ee4b28c),
0590: 49 36 34 28 30 78 35 35 30 63 37 64 63 33 64 35 I64(0x550c7dc3d5
05a0: 66 66 62 34 65 32 29 2c 0a 09 49 36 34 28 30 78 ffb4e2),..I64(0x
05b0: 37 32 62 65 35 64 37 34 66 32 37 62 38 39 36 66 72be5d74f27b896f
05c0: 29 2c 20 49 36 34 28 30 78 38 30 64 65 62 31 66 ), I64(0x80deb1f
05d0: 65 33 62 31 36 39 36 62 31 29 2c 20 49 36 34 28 e3b1696b1), I64(
05e0: 30 78 39 62 64 63 30 36 61 37 32 35 63 37 31 32 0x9bdc06a725c712
05f0: 33 35 29 2c 0a 09 49 36 34 28 30 78 63 31 39 62 35),..I64(0xc19b
0600: 66 31 37 34 63 66 36 39 32 36 39 34 29 2c 20 49 f174cf692694), I
0610: 36 34 28 30 78 65 34 39 62 36 39 63 31 39 65 66 64(0xe49b69c19ef
0620: 31 34 61 64 32 29 2c 20 49 36 34 28 30 78 65 66 14ad2), I64(0xef
0630: 62 65 34 37 38 36 33 38 34 66 32 35 65 33 29 2c be4786384f25e3),
0640: 0a 09 49 36 34 28 30 78 30 66 63 31 39 64 63 36 ..I64(0x0fc19dc6
0650: 38 62 38 63 64 35 62 35 29 2c 20 49 36 34 28 30 8b8cd5b5), I64(0
0660: 78 32 34 30 63 61 31 63 63 37 37 61 63 39 63 36 x240ca1cc77ac9c6
0670: 35 29 2c 20 49 36 34 28 30 78 32 64 65 39 32 63 5), I64(0x2de92c
0680: 36 66 35 39 32 62 30 32 37 35 29 2c 0a 09 49 36 6f592b0275),..I6
0690: 34 28 30 78 34 61 37 34 38 34 61 61 36 65 61 36 4(0x4a7484aa6ea6
06a0: 65 34 38 33 29 2c 20 49 36 34 28 30 78 35 63 62 e483), I64(0x5cb
06b0: 30 61 39 64 63 62 64 34 31 66 62 64 34 29 2c 20 0a9dcbd41fbd4),
06c0: 49 36 34 28 30 78 37 36 66 39 38 38 64 61 38 33 I64(0x76f988da83
06d0: 31 31 35 33 62 35 29 2c 0a 09 49 36 34 28 30 78 1153b5),..I64(0x
06e0: 39 38 33 65 35 31 35 32 65 65 36 36 64 66 61 62 983e5152ee66dfab
06f0: 29 2c 20 49 36 34 28 30 78 61 38 33 31 63 36 36 ), I64(0xa831c66
0700: 64 32 64 62 34 33 32 31 30 29 2c 20 49 36 34 28 d2db43210), I64(
0710: 30 78 62 30 30 33 32 37 63 38 39 38 66 62 32 31 0xb00327c898fb21
0720: 33 66 29 2c 0a 09 49 36 34 28 30 78 62 66 35 39 3f),..I64(0xbf59
0730: 37 66 63 37 62 65 65 66 30 65 65 34 29 2c 20 49 7fc7beef0ee4), I
0740: 36 34 28 30 78 63 36 65 30 30 62 66 33 33 64 61 64(0xc6e00bf33da
0750: 38 38 66 63 32 29 2c 20 49 36 34 28 30 78 64 35 88fc2), I64(0xd5
0760: 61 37 39 31 34 37 39 33 30 61 61 37 32 35 29 2c a79147930aa725),
0770: 0a 09 49 36 34 28 30 78 30 36 63 61 36 33 35 31 ..I64(0x06ca6351
0780: 65 30 30 33 38 32 36 66 29 2c 20 49 36 34 28 30 e003826f), I64(0
0790: 78 31 34 32 39 32 39 36 37 30 61 30 65 36 65 37 x142929670a0e6e7
07a0: 30 29 2c 20 49 36 34 28 30 78 32 37 62 37 30 61 0), I64(0x27b70a
07b0: 38 35 34 36 64 32 32 66 66 63 29 2c 0a 09 49 36 8546d22ffc),..I6
07c0: 34 28 30 78 32 65 31 62 32 31 33 38 35 63 32 36 4(0x2e1b21385c26
07d0: 63 39 32 36 29 2c 20 49 36 34 28 30 78 34 64 32 c926), I64(0x4d2
07e0: 63 36 64 66 63 35 61 63 34 32 61 65 64 29 2c 20 c6dfc5ac42aed),
07f0: 49 36 34 28 30 78 35 33 33 38 30 64 31 33 39 64 I64(0x53380d139d
0800: 39 35 62 33 64 66 29 2c 0a 09 49 36 34 28 30 78 95b3df),..I64(0x
0810: 36 35 30 61 37 33 35 34 38 62 61 66 36 33 64 65 650a73548baf63de
0820: 29 2c 20 49 36 34 28 30 78 37 36 36 61 30 61 62 ), I64(0x766a0ab
0830: 62 33 63 37 37 62 32 61 38 29 2c 20 49 36 34 28 b3c77b2a8), I64(
0840: 30 78 38 31 63 32 63 39 32 65 34 37 65 64 61 65 0x81c2c92e47edae
0850: 65 36 29 2c 0a 09 49 36 34 28 30 78 39 32 37 32 e6),..I64(0x9272
0860: 32 63 38 35 31 34 38 32 33 35 33 62 29 2c 20 49 2c851482353b), I
0870: 36 34 28 30 78 61 32 62 66 65 38 61 31 34 63 66 64(0xa2bfe8a14cf
0880: 31 30 33 36 34 29 2c 20 49 36 34 28 30 78 61 38 10364), I64(0xa8
0890: 31 61 36 36 34 62 62 63 34 32 33 30 30 31 29 2c 1a664bbc423001),
08a0: 0a 09 49 36 34 28 30 78 63 32 34 62 38 62 37 30 ..I64(0xc24b8b70
08b0: 64 30 66 38 39 37 39 31 29 2c 20 49 36 34 28 30 d0f89791), I64(0
08c0: 78 63 37 36 63 35 31 61 33 30 36 35 34 62 65 33 xc76c51a30654be3
08d0: 30 29 2c 20 49 36 34 28 30 78 64 31 39 32 65 38 0), I64(0xd192e8
08e0: 31 39 64 36 65 66 35 32 31 38 29 2c 0a 09 49 36 19d6ef5218),..I6
08f0: 34 28 30 78 64 36 39 39 30 36 32 34 35 35 36 35 4(0xd69906245565
0900: 61 39 31 30 29 2c 20 49 36 34 28 30 78 66 34 30 a910), I64(0xf40
0910: 65 33 35 38 35 35 37 37 31 32 30 32 61 29 2c 20 e35855771202a),
0920: 49 36 34 28 30 78 31 30 36 61 61 30 37 30 33 32 I64(0x106aa07032
0930: 62 62 64 31 62 38 29 2c 0a 09 49 36 34 28 30 78 bbd1b8),..I64(0x
0940: 31 39 61 34 63 31 31 36 62 38 64 32 64 30 63 38 19a4c116b8d2d0c8
0950: 29 2c 20 49 36 34 28 30 78 31 65 33 37 36 63 30 ), I64(0x1e376c0
0960: 38 35 31 34 31 61 62 35 33 29 2c 20 49 36 34 28 85141ab53), I64(
0970: 30 78 32 37 34 38 37 37 34 63 64 66 38 65 65 62 0x2748774cdf8eeb
0980: 39 39 29 2c 0a 09 49 36 34 28 30 78 33 34 62 30 99),..I64(0x34b0
0990: 62 63 62 35 65 31 39 62 34 38 61 38 29 2c 20 49 bcb5e19b48a8), I
09a0: 36 34 28 30 78 33 39 31 63 30 63 62 33 63 35 63 64(0x391c0cb3c5c
09b0: 39 35 61 36 33 29 2c 20 49 36 34 28 30 78 34 65 95a63), I64(0x4e
09c0: 64 38 61 61 34 61 65 33 34 31 38 61 63 62 29 2c d8aa4ae3418acb),
09d0: 0a 09 49 36 34 28 30 78 35 62 39 63 63 61 34 66 ..I64(0x5b9cca4f
09e0: 37 37 36 33 65 33 37 33 29 2c 20 49 36 34 28 30 7763e373), I64(0
09f0: 78 36 38 32 65 36 66 66 33 64 36 62 32 62 38 61 x682e6ff3d6b2b8a
0a00: 33 29 2c 20 49 36 34 28 30 78 37 34 38 66 38 32 3), I64(0x748f82
0a10: 65 65 35 64 65 66 62 32 66 63 29 2c 0a 09 49 36 ee5defb2fc),..I6
0a20: 34 28 30 78 37 38 61 35 36 33 36 66 34 33 31 37 4(0x78a5636f4317
0a30: 32 66 36 30 29 2c 20 49 36 34 28 30 78 38 34 63 2f60), I64(0x84c
0a40: 38 37 38 31 34 61 31 66 30 61 62 37 32 29 2c 20 87814a1f0ab72),
0a50: 49 36 34 28 30 78 38 63 63 37 30 32 30 38 31 61 I64(0x8cc702081a
0a60: 36 34 33 39 65 63 29 2c 0a 09 49 36 34 28 30 78 6439ec),..I64(0x
0a70: 39 30 62 65 66 66 66 61 32 33 36 33 31 65 32 38 90befffa23631e28
0a80: 29 2c 20 49 36 34 28 30 78 61 34 35 30 36 63 65 ), I64(0xa4506ce
0a90: 62 64 65 38 32 62 64 65 39 29 2c 20 49 36 34 28 bde82bde9), I64(
0aa0: 30 78 62 65 66 39 61 33 66 37 62 32 63 36 37 39 0xbef9a3f7b2c679
0ab0: 31 35 29 2c 0a 09 49 36 34 28 30 78 63 36 37 31 15),..I64(0xc671
0ac0: 37 38 66 32 65 33 37 32 35 33 32 62 29 2c 20 49 78f2e372532b), I
0ad0: 36 34 28 30 78 63 61 32 37 33 65 63 65 65 61 32 64(0xca273eceea2
0ae0: 36 36 31 39 63 29 2c 20 49 36 34 28 30 78 64 31 6619c), I64(0xd1
0af0: 38 36 62 38 63 37 32 31 63 30 63 32 30 37 29 2c 86b8c721c0c207),
0b00: 0a 09 49 36 34 28 30 78 65 61 64 61 37 64 64 36 ..I64(0xeada7dd6
0b10: 63 64 65 30 65 62 31 65 29 2c 20 49 36 34 28 30 cde0eb1e), I64(0
0b20: 78 66 35 37 64 34 66 37 66 65 65 36 65 64 31 37 xf57d4f7fee6ed17
0b30: 38 29 2c 20 49 36 34 28 30 78 30 36 66 30 36 37 8), I64(0x06f067
0b40: 61 61 37 32 31 37 36 66 62 61 29 2c 0a 09 49 36 aa72176fba),..I6
0b50: 34 28 30 78 30 61 36 33 37 64 63 35 61 32 63 38 4(0x0a637dc5a2c8
0b60: 39 38 61 36 29 2c 20 49 36 34 28 30 78 31 31 33 98a6), I64(0x113
0b70: 66 39 38 30 34 62 65 66 39 30 64 61 65 29 2c 20 f9804bef90dae),
0b80: 49 36 34 28 30 78 31 62 37 31 30 62 33 35 31 33 I64(0x1b710b3513
0b90: 31 63 34 37 31 62 29 2c 0a 09 49 36 34 28 30 78 1c471b),..I64(0x
0ba0: 32 38 64 62 37 37 66 35 32 33 30 34 37 64 38 34 28db77f523047d84
0bb0: 29 2c 20 49 36 34 28 30 78 33 32 63 61 61 62 37 ), I64(0x32caab7
0bc0: 62 34 30 63 37 32 34 39 33 29 2c 20 49 36 34 28 b40c72493), I64(
0bd0: 30 78 33 63 39 65 62 65 30 61 31 35 63 39 62 65 0x3c9ebe0a15c9be
0be0: 62 63 29 2c 0a 09 49 36 34 28 30 78 34 33 31 64 bc),..I64(0x431d
0bf0: 36 37 63 34 39 63 31 30 30 64 34 63 29 2c 20 49 67c49c100d4c), I
0c00: 36 34 28 30 78 34 63 63 35 64 34 62 65 63 62 33 64(0x4cc5d4becb3
0c10: 65 34 32 62 36 29 2c 20 49 36 34 28 30 78 35 39 e42b6), I64(0x59
0c20: 37 66 32 39 39 63 66 63 36 35 37 65 32 61 29 2c 7f299cfc657e2a),
0c30: 0a 09 49 36 34 28 30 78 35 66 63 62 36 66 61 62 ..I64(0x5fcb6fab
0c40: 33 61 64 36 66 61 65 63 29 2c 20 49 36 34 28 30 3ad6faec), I64(0
0c50: 78 36 63 34 34 31 39 38 63 34 61 34 37 35 38 31 x6c44198c4a47581
0c60: 37 29 0a 7d 3b 0a 0a 2f 2a 20 54 68 65 20 53 48 7).};../* The SH
0c70: 41 35 31 32 2f 33 38 34 20 66 75 6e 63 74 69 6f A512/384 functio
0c80: 6e 73 20 64 65 66 69 6e 65 64 20 62 79 20 46 49 ns defined by FI
0c90: 50 53 20 31 38 30 2d 33 2c 20 34 2e 31 2e 33 20 PS 180-3, 4.1.3
0ca0: 2a 2f 0a 2f 2a 20 4f 70 74 69 6d 69 7a 65 64 20 */./* Optimized
0cb0: 76 65 72 73 69 6f 6e 20 6f 66 20 43 68 28 78 2c version of Ch(x,
0cc0: 79 2c 7a 29 3d 28 28 78 20 26 20 79 29 20 7c 20 y,z)=((x & y) |
0cd0: 28 7e 78 20 26 20 7a 29 29 20 2a 2f 0a 23 64 65 (~x & z)) */.#de
0ce0: 66 69 6e 65 20 43 68 28 78 2c 79 2c 7a 29 20 20 fine Ch(x,y,z)
0cf0: 28 28 7a 29 20 5e 20 28 28 78 29 20 26 20 28 28 ((z) ^ ((x) & ((
0d00: 79 29 20 5e 20 28 7a 29 29 29 29 0a 2f 2a 20 4f y) ^ (z))))./* O
0d10: 70 74 69 6d 69 7a 65 64 20 76 65 72 73 69 6f 6e ptimized version
0d20: 20 6f 66 20 4d 61 6a 28 78 2c 79 2c 7a 29 3d 28 of Maj(x,y,z)=(
0d30: 28 78 20 26 20 79 29 20 5e 20 28 78 20 26 20 7a (x & y) ^ (x & z
0d40: 29 20 5e 20 28 79 20 26 20 7a 29 29 20 2a 2f 0a ) ^ (y & z)) */.
0d50: 23 64 65 66 69 6e 65 20 4d 61 6a 28 78 2c 79 2c #define Maj(x,y,
0d60: 7a 29 20 28 28 28 78 29 20 26 20 28 79 29 29 20 z) (((x) & (y))
0d70: 5e 20 28 28 7a 29 20 26 20 28 28 78 29 20 5e 20 ^ ((z) & ((x) ^
0d80: 28 79 29 29 29 29 0a 0a 23 64 65 66 69 6e 65 20 (y))))..#define
0d90: 53 69 67 6d 61 30 28 78 29 20 28 52 4f 54 52 36 Sigma0(x) (ROTR6
0da0: 34 28 28 78 29 2c 20 32 38 29 20 5e 20 52 4f 54 4((x), 28) ^ ROT
0db0: 52 36 34 28 28 78 29 2c 20 33 34 29 20 5e 20 52 R64((x), 34) ^ R
0dc0: 4f 54 52 36 34 28 28 78 29 2c 20 33 39 29 29 0a OTR64((x), 39)).
0dd0: 23 64 65 66 69 6e 65 20 53 69 67 6d 61 31 28 78 #define Sigma1(x
0de0: 29 20 28 52 4f 54 52 36 34 28 28 78 29 2c 20 31 ) (ROTR64((x), 1
0df0: 34 29 20 5e 20 52 4f 54 52 36 34 28 28 78 29 2c 4) ^ ROTR64((x),
0e00: 20 31 38 29 20 5e 20 52 4f 54 52 36 34 28 28 78 18) ^ ROTR64((x
0e10: 29 2c 20 34 31 29 29 0a 23 64 65 66 69 6e 65 20 ), 41)).#define
0e20: 73 69 67 6d 61 30 28 78 29 20 28 52 4f 54 52 36 sigma0(x) (ROTR6
0e30: 34 28 28 78 29 2c 20 20 31 29 20 5e 20 52 4f 54 4((x), 1) ^ ROT
0e40: 52 36 34 28 28 78 29 2c 20 20 38 29 20 5e 20 28 R64((x), 8) ^ (
0e50: 28 78 29 20 3e 3e 20 37 29 29 0a 23 64 65 66 69 (x) >> 7)).#defi
0e60: 6e 65 20 73 69 67 6d 61 31 28 78 29 20 28 52 4f ne sigma1(x) (RO
0e70: 54 52 36 34 28 28 78 29 2c 20 31 39 29 20 5e 20 TR64((x), 19) ^
0e80: 52 4f 54 52 36 34 28 28 78 29 2c 20 36 31 29 20 ROTR64((x), 61)
0e90: 5e 20 28 28 78 29 20 3e 3e 20 36 29 29 0a 0a 2f ^ ((x) >> 6))../
0ea0: 2a 20 52 65 63 61 6c 63 75 6c 61 74 65 20 65 6c * Recalculate el
0eb0: 65 6d 65 6e 74 20 6e 2d 74 68 20 6f 66 20 63 69 ement n-th of ci
0ec0: 72 63 75 6c 61 72 20 62 75 66 66 65 72 20 57 20 rcular buffer W
0ed0: 75 73 69 6e 67 20 66 6f 72 6d 75 6c 61 0a 20 2a using formula. *
0ee0: 20 20 20 57 5b 6e 5d 20 3d 20 73 69 67 6d 61 31 W[n] = sigma1
0ef0: 28 57 5b 6e 20 2d 20 32 5d 29 20 2b 20 57 5b 6e (W[n - 2]) + W[n
0f00: 20 2d 20 37 5d 20 2b 20 73 69 67 6d 61 30 28 57 - 7] + sigma0(W
0f10: 5b 6e 20 2d 20 31 35 5d 29 20 2b 20 57 5b 6e 20 [n - 15]) + W[n
0f20: 2d 20 31 36 5d 3b 20 2a 2f 0a 23 64 65 66 69 6e - 16]; */.#defin
0f30: 65 20 52 45 43 41 4c 43 55 4c 41 54 45 5f 57 28 e RECALCULATE_W(
0f40: 57 2c 6e 29 20 28 57 5b 6e 5d 20 2b 3d 20 5c 0a W,n) (W[n] += \.
0f50: 09 28 73 69 67 6d 61 31 28 57 5b 28 6e 20 2d 20 .(sigma1(W[(n -
0f60: 32 29 20 26 20 31 35 5d 29 20 2b 20 57 5b 28 6e 2) & 15]) + W[(n
0f70: 20 2d 20 37 29 20 26 20 31 35 5d 20 2b 20 73 69 - 7) & 15] + si
0f80: 67 6d 61 30 28 57 5b 28 6e 20 2d 20 31 35 29 20 gma0(W[(n - 15)
0f90: 26 20 31 35 5d 29 29 29 0a 0a 23 64 65 66 69 6e & 15])))..#defin
0fa0: 65 20 52 4f 55 4e 44 28 61 2c 62 2c 63 2c 64 2c e ROUND(a,b,c,d,
0fb0: 65 2c 66 2c 67 2c 68 2c 6b 2c 64 61 74 61 29 20 e,f,g,h,k,data)
0fc0: 7b 20 5c 0a 09 75 69 6e 74 36 34 5f 74 20 54 31 { \..uint64_t T1
0fd0: 20 3d 20 68 20 2b 20 53 69 67 6d 61 31 28 65 29 = h + Sigma1(e)
0fe0: 20 2b 20 43 68 28 65 2c 66 2c 67 29 20 2b 20 6b + Ch(e,f,g) + k
0ff0: 20 2b 20 28 64 61 74 61 29 3b 20 5c 0a 09 64 20 + (data); \..d
1000: 2b 3d 20 54 31 2c 20 68 20 3d 20 54 31 20 2b 20 += T1, h = T1 +
1010: 53 69 67 6d 61 30 28 61 29 20 2b 20 4d 61 6a 28 Sigma0(a) + Maj(
1020: 61 2c 62 2c 63 29 3b 20 7d 0a 23 64 65 66 69 6e a,b,c); }.#defin
1030: 65 20 52 4f 55 4e 44 5f 31 5f 31 36 28 61 2c 62 e ROUND_1_16(a,b
1040: 2c 63 2c 64 2c 65 2c 66 2c 67 2c 68 2c 6e 29 20 ,c,d,e,f,g,h,n)
1050: 5c 0a 09 52 4f 55 4e 44 28 61 2c 62 2c 63 2c 64 \..ROUND(a,b,c,d
1060: 2c 65 2c 66 2c 67 2c 68 2c 20 72 68 61 73 68 5f ,e,f,g,h, rhash_
1070: 6b 35 31 32 5b 6e 5d 2c 20 57 5b 6e 5d 20 3d 20 k512[n], W[n] =
1080: 62 65 32 6d 65 5f 36 34 28 62 6c 6f 63 6b 5b 6e be2me_64(block[n
1090: 5d 29 29 0a 23 64 65 66 69 6e 65 20 52 4f 55 4e ])).#define ROUN
10a0: 44 5f 31 37 5f 38 30 28 61 2c 62 2c 63 2c 64 2c D_17_80(a,b,c,d,
10b0: 65 2c 66 2c 67 2c 68 2c 6e 29 20 5c 0a 09 52 4f e,f,g,h,n) \..RO
10c0: 55 4e 44 28 61 2c 62 2c 63 2c 64 2c 65 2c 66 2c UND(a,b,c,d,e,f,
10d0: 67 2c 68 2c 20 6b 5b 6e 5d 2c 20 52 45 43 41 4c g,h, k[n], RECAL
10e0: 43 55 4c 41 54 45 5f 57 28 57 2c 20 6e 29 29 0a CULATE_W(W, n)).
10f0: 0a 2f 2a 2a 0a 20 2a 20 49 6e 69 74 69 61 6c 69 ./**. * Initiali
1100: 7a 65 20 63 6f 6e 74 65 78 74 20 62 65 66 6f 72 ze context befor
1110: 65 20 63 61 6c 63 75 6c 61 74 69 6e 67 20 68 61 e calculating ha
1120: 73 68 2e 0a 20 2a 0a 20 2a 20 40 70 61 72 61 6d sh.. *. * @param
1130: 20 63 74 78 20 63 6f 6e 74 65 78 74 20 74 6f 20 ctx context to
1140: 69 6e 69 74 69 61 6c 69 7a 65 0a 20 2a 2f 0a 76 initialize. */.v
1150: 6f 69 64 20 72 68 61 73 68 5f 73 68 61 35 31 32 oid rhash_sha512
1160: 5f 69 6e 69 74 28 73 68 61 35 31 32 5f 63 74 78 _init(sha512_ctx
1170: 20 2a 63 74 78 29 0a 7b 0a 09 2f 2a 20 49 6e 69 *ctx).{../* Ini
1180: 74 69 61 6c 20 76 61 6c 75 65 73 2e 20 54 68 65 tial values. The
1190: 73 65 20 77 6f 72 64 73 20 77 65 72 65 20 6f 62 se words were ob
11a0: 74 61 69 6e 65 64 20 62 79 20 74 61 6b 69 6e 67 tained by taking
11b0: 20 74 68 65 20 66 69 72 73 74 20 33 32 0a 09 20 the first 32..
11c0: 2a 20 62 69 74 73 20 6f 66 20 74 68 65 20 66 72 * bits of the fr
11d0: 61 63 74 69 6f 6e 61 6c 20 70 61 72 74 73 20 6f actional parts o
11e0: 66 20 74 68 65 20 73 71 75 61 72 65 20 72 6f 6f f the square roo
11f0: 74 73 20 6f 66 20 74 68 65 20 66 69 72 73 74 0a ts of the first.
1200: 09 20 2a 20 65 69 67 68 74 20 70 72 69 6d 65 20 . * eight prime
1210: 6e 75 6d 62 65 72 73 2e 20 2a 2f 0a 09 73 74 61 numbers. */..sta
1220: 74 69 63 20 63 6f 6e 73 74 20 75 69 6e 74 36 34 tic const uint64
1230: 5f 74 20 53 48 41 35 31 32 5f 48 30 5b 38 5d 20 _t SHA512_H0[8]
1240: 3d 20 7b 0a 09 09 49 36 34 28 30 78 36 61 30 39 = {...I64(0x6a09
1250: 65 36 36 37 66 33 62 63 63 39 30 38 29 2c 20 49 e667f3bcc908), I
1260: 36 34 28 30 78 62 62 36 37 61 65 38 35 38 34 63 64(0xbb67ae8584c
1270: 61 61 37 33 62 29 2c 20 49 36 34 28 30 78 33 63 aa73b), I64(0x3c
1280: 36 65 66 33 37 32 66 65 39 34 66 38 32 62 29 2c 6ef372fe94f82b),
1290: 0a 09 09 49 36 34 28 30 78 61 35 34 66 66 35 33 ...I64(0xa54ff53
12a0: 61 35 66 31 64 33 36 66 31 29 2c 20 49 36 34 28 a5f1d36f1), I64(
12b0: 30 78 35 31 30 65 35 32 37 66 61 64 65 36 38 32 0x510e527fade682
12c0: 64 31 29 2c 20 49 36 34 28 30 78 39 62 30 35 36 d1), I64(0x9b056
12d0: 38 38 63 32 62 33 65 36 63 31 66 29 2c 0a 09 09 88c2b3e6c1f),...
12e0: 49 36 34 28 30 78 31 66 38 33 64 39 61 62 66 62 I64(0x1f83d9abfb
12f0: 34 31 62 64 36 62 29 2c 20 49 36 34 28 30 78 35 41bd6b), I64(0x5
1300: 62 65 30 63 64 31 39 31 33 37 65 32 31 37 39 29 be0cd19137e2179)
1310: 0a 09 7d 3b 0a 0a 09 63 74 78 2d 3e 6c 65 6e 67 ..};...ctx->leng
1320: 74 68 20 3d 20 30 3b 0a 09 63 74 78 2d 3e 64 69 th = 0;..ctx->di
1330: 67 65 73 74 5f 6c 65 6e 67 74 68 20 3d 20 73 68 gest_length = sh
1340: 61 35 31 32 5f 68 61 73 68 5f 73 69 7a 65 3b 0a a512_hash_size;.
1350: 0a 09 2f 2a 20 69 6e 69 74 69 61 6c 69 7a 65 20 ../* initialize
1360: 61 6c 67 6f 72 69 74 68 6d 20 73 74 61 74 65 20 algorithm state
1370: 2a 2f 0a 09 6d 65 6d 63 70 79 28 63 74 78 2d 3e */..memcpy(ctx->
1380: 68 61 73 68 2c 20 53 48 41 35 31 32 5f 48 30 2c hash, SHA512_H0,
1390: 20 73 69 7a 65 6f 66 28 63 74 78 2d 3e 68 61 73 sizeof(ctx->has
13a0: 68 29 29 3b 0a 7d 0a 0a 2f 2a 2a 0a 20 2a 20 49 h));.}../**. * I
13b0: 6e 69 74 69 61 6c 69 7a 65 20 63 6f 6e 74 65 78 nitialize contex
13c0: 74 20 62 65 66 6f 72 65 20 63 61 6c 63 75 6c 61 t before calcula
13d0: 69 6e 67 20 68 61 73 68 2e 0a 20 2a 0a 20 2a 20 ing hash.. *. *
13e0: 40 70 61 72 61 6d 20 63 74 78 20 63 6f 6e 74 65 @param ctx conte
13f0: 78 74 20 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65 xt to initialize
1400: 0a 20 2a 2f 0a 76 6f 69 64 20 72 68 61 73 68 5f . */.void rhash_
1410: 73 68 61 33 38 34 5f 69 6e 69 74 28 73 74 72 75 sha384_init(stru
1420: 63 74 20 73 68 61 35 31 32 5f 63 74 78 20 2a 63 ct sha512_ctx *c
1430: 74 78 29 0a 7b 0a 09 2f 2a 20 49 6e 69 74 69 61 tx).{../* Initia
1440: 6c 20 76 61 6c 75 65 73 20 66 72 6f 6d 20 46 49 l values from FI
1450: 50 53 20 31 38 30 2d 33 2e 20 54 68 65 73 65 20 PS 180-3. These
1460: 77 6f 72 64 73 20 77 65 72 65 20 6f 62 74 61 69 words were obtai
1470: 6e 65 64 20 62 79 20 74 61 6b 69 6e 67 0a 09 20 ned by taking..
1480: 2a 20 74 68 65 20 66 69 72 73 74 20 73 69 78 74 * the first sixt
1490: 79 2d 66 6f 75 72 20 62 69 74 73 20 6f 66 20 74 y-four bits of t
14a0: 68 65 20 66 72 61 63 74 69 6f 6e 61 6c 20 70 61 he fractional pa
14b0: 72 74 73 20 6f 66 20 74 68 65 20 73 71 75 61 72 rts of the squar
14c0: 65 0a 09 20 2a 20 72 6f 6f 74 73 20 6f 66 20 6e e.. * roots of n
14d0: 69 6e 74 68 20 74 68 72 6f 75 67 68 20 73 69 78 inth through six
14e0: 74 65 65 6e 74 68 20 70 72 69 6d 65 20 6e 75 6d teenth prime num
14f0: 62 65 72 73 2e 20 2a 2f 0a 09 73 74 61 74 69 63 bers. */..static
1500: 20 63 6f 6e 73 74 20 75 69 6e 74 36 34 5f 74 20 const uint64_t
1510: 53 48 41 33 38 34 5f 48 30 5b 38 5d 20 3d 20 7b SHA384_H0[8] = {
1520: 0a 09 09 49 36 34 28 30 78 63 62 62 62 39 64 35 ...I64(0xcbbb9d5
1530: 64 63 31 30 35 39 65 64 38 29 2c 20 49 36 34 28 dc1059ed8), I64(
1540: 30 78 36 32 39 61 32 39 32 61 33 36 37 63 64 35 0x629a292a367cd5
1550: 30 37 29 2c 20 49 36 34 28 30 78 39 31 35 39 30 07), I64(0x91590
1560: 31 35 61 33 30 37 30 64 64 31 37 29 2c 0a 09 09 15a3070dd17),...
1570: 49 36 34 28 30 78 31 35 32 66 65 63 64 38 66 37 I64(0x152fecd8f7
1580: 30 65 35 39 33 39 29 2c 20 49 36 34 28 30 78 36 0e5939), I64(0x6
1590: 37 33 33 32 36 36 37 66 66 63 30 30 62 33 31 29 7332667ffc00b31)
15a0: 2c 20 49 36 34 28 30 78 38 65 62 34 34 61 38 37 , I64(0x8eb44a87
15b0: 36 38 35 38 31 35 31 31 29 2c 0a 09 09 49 36 34 68581511),...I64
15c0: 28 30 78 64 62 30 63 32 65 30 64 36 34 66 39 38 (0xdb0c2e0d64f98
15d0: 66 61 37 29 2c 20 49 36 34 28 30 78 34 37 62 35 fa7), I64(0x47b5
15e0: 34 38 31 64 62 65 66 61 34 66 61 34 29 0a 09 7d 481dbefa4fa4)..}
15f0: 3b 0a 0a 09 63 74 78 2d 3e 6c 65 6e 67 74 68 20 ;...ctx->length
1600: 3d 20 30 3b 0a 09 63 74 78 2d 3e 64 69 67 65 73 = 0;..ctx->diges
1610: 74 5f 6c 65 6e 67 74 68 20 3d 20 73 68 61 33 38 t_length = sha38
1620: 34 5f 68 61 73 68 5f 73 69 7a 65 3b 0a 0a 09 6d 4_hash_size;...m
1630: 65 6d 63 70 79 28 63 74 78 2d 3e 68 61 73 68 2c emcpy(ctx->hash,
1640: 20 53 48 41 33 38 34 5f 48 30 2c 20 73 69 7a 65 SHA384_H0, size
1650: 6f 66 28 63 74 78 2d 3e 68 61 73 68 29 29 3b 0a of(ctx->hash));.
1660: 7d 0a 0a 2f 2a 2a 0a 20 2a 20 54 68 65 20 63 6f }../**. * The co
1670: 72 65 20 74 72 61 6e 73 66 6f 72 6d 61 74 69 6f re transformatio
1680: 6e 2e 20 50 72 6f 63 65 73 73 20 61 20 35 31 32 n. Process a 512
1690: 2d 62 69 74 20 62 6c 6f 63 6b 2e 0a 20 2a 0a 20 -bit block.. *.
16a0: 2a 20 40 70 61 72 61 6d 20 68 61 73 68 20 61 6c * @param hash al
16b0: 67 6f 72 69 74 68 6d 20 73 74 61 74 65 0a 20 2a gorithm state. *
16c0: 20 40 70 61 72 61 6d 20 62 6c 6f 63 6b 20 74 68 @param block th
16d0: 65 20 6d 65 73 73 61 67 65 20 62 6c 6f 63 6b 20 e message block
16e0: 74 6f 20 70 72 6f 63 65 73 73 0a 20 2a 2f 0a 73 to process. */.s
16f0: 74 61 74 69 63 20 76 6f 69 64 20 72 68 61 73 68 tatic void rhash
1700: 5f 73 68 61 35 31 32 5f 70 72 6f 63 65 73 73 5f _sha512_process_
1710: 62 6c 6f 63 6b 28 75 69 6e 74 36 34 5f 74 20 68 block(uint64_t h
1720: 61 73 68 5b 38 5d 2c 20 75 69 6e 74 36 34 5f 74 ash[8], uint64_t
1730: 20 62 6c 6f 63 6b 5b 31 36 5d 29 0a 7b 0a 09 75 block[16]).{..u
1740: 69 6e 74 36 34 5f 74 20 41 2c 20 42 2c 20 43 2c int64_t A, B, C,
1750: 20 44 2c 20 45 2c 20 46 2c 20 47 2c 20 48 3b 0a D, E, F, G, H;.
1760: 09 75 69 6e 74 36 34 5f 74 20 57 5b 31 36 5d 3b .uint64_t W[16];
1770: 0a 09 63 6f 6e 73 74 20 75 69 6e 74 36 34 5f 74 ..const uint64_t
1780: 20 2a 6b 3b 0a 09 69 6e 74 20 69 3b 0a 0a 09 41 *k;..int i;...A
1790: 20 3d 20 68 61 73 68 5b 30 5d 2c 20 42 20 3d 20 = hash[0], B =
17a0: 68 61 73 68 5b 31 5d 2c 20 43 20 3d 20 68 61 73 hash[1], C = has
17b0: 68 5b 32 5d 2c 20 44 20 3d 20 68 61 73 68 5b 33 h[2], D = hash[3
17c0: 5d 3b 0a 09 45 20 3d 20 68 61 73 68 5b 34 5d 2c ];..E = hash[4],
17d0: 20 46 20 3d 20 68 61 73 68 5b 35 5d 2c 20 47 20 F = hash[5], G
17e0: 3d 20 68 61 73 68 5b 36 5d 2c 20 48 20 3d 20 68 = hash[6], H = h
17f0: 61 73 68 5b 37 5d 3b 0a 0a 09 2f 2a 20 43 6f 6d ash[7];.../* Com
1800: 70 75 74 65 20 53 48 41 20 75 73 69 6e 67 20 61 pute SHA using a
1810: 6c 74 65 72 6e 61 74 65 20 4d 65 74 68 6f 64 3a lternate Method:
1820: 20 46 49 50 53 20 31 38 30 2d 33 20 36 2e 31 2e FIPS 180-3 6.1.
1830: 33 20 2a 2f 0a 09 52 4f 55 4e 44 5f 31 5f 31 36 3 */..ROUND_1_16
1840: 28 41 2c 20 42 2c 20 43 2c 20 44 2c 20 45 2c 20 (A, B, C, D, E,
1850: 46 2c 20 47 2c 20 48 2c 20 30 29 3b 0a 09 52 4f F, G, H, 0);..RO
1860: 55 4e 44 5f 31 5f 31 36 28 48 2c 20 41 2c 20 42 UND_1_16(H, A, B
1870: 2c 20 43 2c 20 44 2c 20 45 2c 20 46 2c 20 47 2c , C, D, E, F, G,
1880: 20 31 29 3b 0a 09 52 4f 55 4e 44 5f 31 5f 31 36 1);..ROUND_1_16
1890: 28 47 2c 20 48 2c 20 41 2c 20 42 2c 20 43 2c 20 (G, H, A, B, C,
18a0: 44 2c 20 45 2c 20 46 2c 20 32 29 3b 0a 09 52 4f D, E, F, 2);..RO
18b0: 55 4e 44 5f 31 5f 31 36 28 46 2c 20 47 2c 20 48 UND_1_16(F, G, H
18c0: 2c 20 41 2c 20 42 2c 20 43 2c 20 44 2c 20 45 2c , A, B, C, D, E,
18d0: 20 33 29 3b 0a 09 52 4f 55 4e 44 5f 31 5f 31 36 3);..ROUND_1_16
18e0: 28 45 2c 20 46 2c 20 47 2c 20 48 2c 20 41 2c 20 (E, F, G, H, A,
18f0: 42 2c 20 43 2c 20 44 2c 20 34 29 3b 0a 09 52 4f B, C, D, 4);..RO
1900: 55 4e 44 5f 31 5f 31 36 28 44 2c 20 45 2c 20 46 UND_1_16(D, E, F
1910: 2c 20 47 2c 20 48 2c 20 41 2c 20 42 2c 20 43 2c , G, H, A, B, C,
1920: 20 35 29 3b 0a 09 52 4f 55 4e 44 5f 31 5f 31 36 5);..ROUND_1_16
1930: 28 43 2c 20 44 2c 20 45 2c 20 46 2c 20 47 2c 20 (C, D, E, F, G,
1940: 48 2c 20 41 2c 20 42 2c 20 36 29 3b 0a 09 52 4f H, A, B, 6);..RO
1950: 55 4e 44 5f 31 5f 31 36 28 42 2c 20 43 2c 20 44 UND_1_16(B, C, D
1960: 2c 20 45 2c 20 46 2c 20 47 2c 20 48 2c 20 41 2c , E, F, G, H, A,
1970: 20 37 29 3b 0a 09 52 4f 55 4e 44 5f 31 5f 31 36 7);..ROUND_1_16
1980: 28 41 2c 20 42 2c 20 43 2c 20 44 2c 20 45 2c 20 (A, B, C, D, E,
1990: 46 2c 20 47 2c 20 48 2c 20 38 29 3b 0a 09 52 4f F, G, H, 8);..RO
19a0: 55 4e 44 5f 31 5f 31 36 28 48 2c 20 41 2c 20 42 UND_1_16(H, A, B
19b0: 2c 20 43 2c 20 44 2c 20 45 2c 20 46 2c 20 47 2c , C, D, E, F, G,
19c0: 20 39 29 3b 0a 09 52 4f 55 4e 44 5f 31 5f 31 36 9);..ROUND_1_16
19d0: 28 47 2c 20 48 2c 20 41 2c 20 42 2c 20 43 2c 20 (G, H, A, B, C,
19e0: 44 2c 20 45 2c 20 46 2c 20 31 30 29 3b 0a 09 52 D, E, F, 10);..R
19f0: 4f 55 4e 44 5f 31 5f 31 36 28 46 2c 20 47 2c 20 OUND_1_16(F, G,
1a00: 48 2c 20 41 2c 20 42 2c 20 43 2c 20 44 2c 20 45 H, A, B, C, D, E
1a10: 2c 20 31 31 29 3b 0a 09 52 4f 55 4e 44 5f 31 5f , 11);..ROUND_1_
1a20: 31 36 28 45 2c 20 46 2c 20 47 2c 20 48 2c 20 41 16(E, F, G, H, A
1a30: 2c 20 42 2c 20 43 2c 20 44 2c 20 31 32 29 3b 0a , B, C, D, 12);.
1a40: 09 52 4f 55 4e 44 5f 31 5f 31 36 28 44 2c 20 45 .ROUND_1_16(D, E
1a50: 2c 20 46 2c 20 47 2c 20 48 2c 20 41 2c 20 42 2c , F, G, H, A, B,
1a60: 20 43 2c 20 31 33 29 3b 0a 09 52 4f 55 4e 44 5f C, 13);..ROUND_
1a70: 31 5f 31 36 28 43 2c 20 44 2c 20 45 2c 20 46 2c 1_16(C, D, E, F,
1a80: 20 47 2c 20 48 2c 20 41 2c 20 42 2c 20 31 34 29 G, H, A, B, 14)
1a90: 3b 0a 09 52 4f 55 4e 44 5f 31 5f 31 36 28 42 2c ;..ROUND_1_16(B,
1aa0: 20 43 2c 20 44 2c 20 45 2c 20 46 2c 20 47 2c 20 C, D, E, F, G,
1ab0: 48 2c 20 41 2c 20 31 35 29 3b 0a 0a 09 66 6f 72 H, A, 15);...for
1ac0: 20 28 69 20 3d 20 31 36 2c 20 6b 20 3d 20 26 72 (i = 16, k = &r
1ad0: 68 61 73 68 5f 6b 35 31 32 5b 31 36 5d 3b 20 69 hash_k512[16]; i
1ae0: 20 3c 20 38 30 3b 20 69 20 2b 3d 20 31 36 2c 20 < 80; i += 16,
1af0: 6b 20 2b 3d 20 31 36 29 20 7b 0a 09 09 52 4f 55 k += 16) {...ROU
1b00: 4e 44 5f 31 37 5f 38 30 28 41 2c 20 42 2c 20 43 ND_17_80(A, B, C
1b10: 2c 20 44 2c 20 45 2c 20 46 2c 20 47 2c 20 48 2c , D, E, F, G, H,
1b20: 20 20 30 29 3b 0a 09 09 52 4f 55 4e 44 5f 31 37 0);...ROUND_17
1b30: 5f 38 30 28 48 2c 20 41 2c 20 42 2c 20 43 2c 20 _80(H, A, B, C,
1b40: 44 2c 20 45 2c 20 46 2c 20 47 2c 20 20 31 29 3b D, E, F, G, 1);
1b50: 0a 09 09 52 4f 55 4e 44 5f 31 37 5f 38 30 28 47 ...ROUND_17_80(G
1b60: 2c 20 48 2c 20 41 2c 20 42 2c 20 43 2c 20 44 2c , H, A, B, C, D,
1b70: 20 45 2c 20 46 2c 20 20 32 29 3b 0a 09 09 52 4f E, F, 2);...RO
1b80: 55 4e 44 5f 31 37 5f 38 30 28 46 2c 20 47 2c 20 UND_17_80(F, G,
1b90: 48 2c 20 41 2c 20 42 2c 20 43 2c 20 44 2c 20 45 H, A, B, C, D, E
1ba0: 2c 20 20 33 29 3b 0a 09 09 52 4f 55 4e 44 5f 31 , 3);...ROUND_1
1bb0: 37 5f 38 30 28 45 2c 20 46 2c 20 47 2c 20 48 2c 7_80(E, F, G, H,
1bc0: 20 41 2c 20 42 2c 20 43 2c 20 44 2c 20 20 34 29 A, B, C, D, 4)
1bd0: 3b 0a 09 09 52 4f 55 4e 44 5f 31 37 5f 38 30 28 ;...ROUND_17_80(
1be0: 44 2c 20 45 2c 20 46 2c 20 47 2c 20 48 2c 20 41 D, E, F, G, H, A
1bf0: 2c 20 42 2c 20 43 2c 20 20 35 29 3b 0a 09 09 52 , B, C, 5);...R
1c00: 4f 55 4e 44 5f 31 37 5f 38 30 28 43 2c 20 44 2c OUND_17_80(C, D,
1c10: 20 45 2c 20 46 2c 20 47 2c 20 48 2c 20 41 2c 20 E, F, G, H, A,
1c20: 42 2c 20 20 36 29 3b 0a 09 09 52 4f 55 4e 44 5f B, 6);...ROUND_
1c30: 31 37 5f 38 30 28 42 2c 20 43 2c 20 44 2c 20 45 17_80(B, C, D, E
1c40: 2c 20 46 2c 20 47 2c 20 48 2c 20 41 2c 20 20 37 , F, G, H, A, 7
1c50: 29 3b 0a 09 09 52 4f 55 4e 44 5f 31 37 5f 38 30 );...ROUND_17_80
1c60: 28 41 2c 20 42 2c 20 43 2c 20 44 2c 20 45 2c 20 (A, B, C, D, E,
1c70: 46 2c 20 47 2c 20 48 2c 20 20 38 29 3b 0a 09 09 F, G, H, 8);...
1c80: 52 4f 55 4e 44 5f 31 37 5f 38 30 28 48 2c 20 41 ROUND_17_80(H, A
1c90: 2c 20 42 2c 20 43 2c 20 44 2c 20 45 2c 20 46 2c , B, C, D, E, F,
1ca0: 20 47 2c 20 20 39 29 3b 0a 09 09 52 4f 55 4e 44 G, 9);...ROUND
1cb0: 5f 31 37 5f 38 30 28 47 2c 20 48 2c 20 41 2c 20 _17_80(G, H, A,
1cc0: 42 2c 20 43 2c 20 44 2c 20 45 2c 20 46 2c 20 31 B, C, D, E, F, 1
1cd0: 30 29 3b 0a 09 09 52 4f 55 4e 44 5f 31 37 5f 38 0);...ROUND_17_8
1ce0: 30 28 46 2c 20 47 2c 20 48 2c 20 41 2c 20 42 2c 0(F, G, H, A, B,
1cf0: 20 43 2c 20 44 2c 20 45 2c 20 31 31 29 3b 0a 09 C, D, E, 11);..
1d00: 09 52 4f 55 4e 44 5f 31 37 5f 38 30 28 45 2c 20 .ROUND_17_80(E,
1d10: 46 2c 20 47 2c 20 48 2c 20 41 2c 20 42 2c 20 43 F, G, H, A, B, C
1d20: 2c 20 44 2c 20 31 32 29 3b 0a 09 09 52 4f 55 4e , D, 12);...ROUN
1d30: 44 5f 31 37 5f 38 30 28 44 2c 20 45 2c 20 46 2c D_17_80(D, E, F,
1d40: 20 47 2c 20 48 2c 20 41 2c 20 42 2c 20 43 2c 20 G, H, A, B, C,
1d50: 31 33 29 3b 0a 09 09 52 4f 55 4e 44 5f 31 37 5f 13);...ROUND_17_
1d60: 38 30 28 43 2c 20 44 2c 20 45 2c 20 46 2c 20 47 80(C, D, E, F, G
1d70: 2c 20 48 2c 20 41 2c 20 42 2c 20 31 34 29 3b 0a , H, A, B, 14);.
1d80: 09 09 52 4f 55 4e 44 5f 31 37 5f 38 30 28 42 2c ..ROUND_17_80(B,
1d90: 20 43 2c 20 44 2c 20 45 2c 20 46 2c 20 47 2c 20 C, D, E, F, G,
1da0: 48 2c 20 41 2c 20 31 35 29 3b 0a 09 7d 0a 0a 09 H, A, 15);..}...
1db0: 68 61 73 68 5b 30 5d 20 2b 3d 20 41 2c 20 68 61 hash[0] += A, ha
1dc0: 73 68 5b 31 5d 20 2b 3d 20 42 2c 20 68 61 73 68 sh[1] += B, hash
1dd0: 5b 32 5d 20 2b 3d 20 43 2c 20 68 61 73 68 5b 33 [2] += C, hash[3
1de0: 5d 20 2b 3d 20 44 3b 0a 09 68 61 73 68 5b 34 5d ] += D;..hash[4]
1df0: 20 2b 3d 20 45 2c 20 68 61 73 68 5b 35 5d 20 2b += E, hash[5] +
1e00: 3d 20 46 2c 20 68 61 73 68 5b 36 5d 20 2b 3d 20 = F, hash[6] +=
1e10: 47 2c 20 68 61 73 68 5b 37 5d 20 2b 3d 20 48 3b G, hash[7] += H;
1e20: 0a 7d 0a 0a 2f 2a 2a 0a 20 2a 20 43 61 6c 63 75 .}../**. * Calcu
1e30: 6c 61 74 65 20 6d 65 73 73 61 67 65 20 68 61 73 late message has
1e40: 68 2e 0a 20 2a 20 43 61 6e 20 62 65 20 63 61 6c h.. * Can be cal
1e50: 6c 65 64 20 72 65 70 65 61 74 65 64 6c 79 20 77 led repeatedly w
1e60: 69 74 68 20 63 68 75 6e 6b 73 20 6f 66 20 74 68 ith chunks of th
1e70: 65 20 6d 65 73 73 61 67 65 20 74 6f 20 62 65 20 e message to be
1e80: 68 61 73 68 65 64 2e 0a 20 2a 0a 20 2a 20 40 70 hashed.. *. * @p
1e90: 61 72 61 6d 20 63 74 78 20 74 68 65 20 61 6c 67 aram ctx the alg
1ea0: 6f 72 69 74 68 6d 20 63 6f 6e 74 65 78 74 20 63 orithm context c
1eb0: 6f 6e 74 61 69 6e 69 6e 67 20 63 75 72 72 65 6e ontaining curren
1ec0: 74 20 68 61 73 68 69 6e 67 20 73 74 61 74 65 0a t hashing state.
1ed0: 20 2a 20 40 70 61 72 61 6d 20 6d 73 67 20 6d 65 * @param msg me
1ee0: 73 73 61 67 65 20 63 68 75 6e 6b 0a 20 2a 20 40 ssage chunk. * @
1ef0: 70 61 72 61 6d 20 73 69 7a 65 20 6c 65 6e 67 74 param size lengt
1f00: 68 20 6f 66 20 74 68 65 20 6d 65 73 73 61 67 65 h of the message
1f10: 20 63 68 75 6e 6b 0a 20 2a 2f 0a 76 6f 69 64 20 chunk. */.void
1f20: 72 68 61 73 68 5f 73 68 61 35 31 32 5f 75 70 64 rhash_sha512_upd
1f30: 61 74 65 28 73 68 61 35 31 32 5f 63 74 78 20 2a ate(sha512_ctx *
1f40: 63 74 78 2c 20 63 6f 6e 73 74 20 75 6e 73 69 67 ctx, const unsig
1f50: 6e 65 64 20 63 68 61 72 20 2a 6d 73 67 2c 20 73 ned char *msg, s
1f60: 69 7a 65 5f 74 20 73 69 7a 65 29 0a 7b 0a 09 73 ize_t size).{..s
1f70: 69 7a 65 5f 74 20 69 6e 64 65 78 20 3d 20 28 73 ize_t index = (s
1f80: 69 7a 65 5f 74 29 63 74 78 2d 3e 6c 65 6e 67 74 ize_t)ctx->lengt
1f90: 68 20 26 20 31 32 37 3b 0a 09 63 74 78 2d 3e 6c h & 127;..ctx->l
1fa0: 65 6e 67 74 68 20 2b 3d 20 73 69 7a 65 3b 0a 0a ength += size;..
1fb0: 09 2f 2a 20 66 69 6c 6c 20 70 61 72 74 69 61 6c ./* fill partial
1fc0: 20 62 6c 6f 63 6b 20 2a 2f 0a 09 69 66 20 28 69 block */..if (i
1fd0: 6e 64 65 78 29 20 7b 0a 09 09 73 69 7a 65 5f 74 ndex) {...size_t
1fe0: 20 6c 65 66 74 20 3d 20 73 68 61 35 31 32 5f 62 left = sha512_b
1ff0: 6c 6f 63 6b 5f 73 69 7a 65 20 2d 20 69 6e 64 65 lock_size - inde
2000: 78 3b 0a 09 09 6d 65 6d 63 70 79 28 28 63 68 61 x;...memcpy((cha
2010: 72 2a 29 63 74 78 2d 3e 6d 65 73 73 61 67 65 20 r*)ctx->message
2020: 2b 20 69 6e 64 65 78 2c 20 6d 73 67 2c 20 28 73 + index, msg, (s
2030: 69 7a 65 20 3c 20 6c 65 66 74 20 3f 20 73 69 7a ize < left ? siz
2040: 65 20 3a 20 6c 65 66 74 29 29 3b 0a 09 09 69 66 e : left));...if
2050: 20 28 73 69 7a 65 20 3c 20 6c 65 66 74 29 20 72 (size < left) r
2060: 65 74 75 72 6e 3b 0a 0a 09 09 2f 2a 20 70 72 6f eturn;..../* pro
2070: 63 65 73 73 20 70 61 72 74 69 61 6c 20 62 6c 6f cess partial blo
2080: 63 6b 20 2a 2f 0a 09 09 72 68 61 73 68 5f 73 68 ck */...rhash_sh
2090: 61 35 31 32 5f 70 72 6f 63 65 73 73 5f 62 6c 6f a512_process_blo
20a0: 63 6b 28 63 74 78 2d 3e 68 61 73 68 2c 20 63 74 ck(ctx->hash, ct
20b0: 78 2d 3e 6d 65 73 73 61 67 65 29 3b 0a 09 09 6d x->message);...m
20c0: 73 67 20 20 2b 3d 20 6c 65 66 74 3b 0a 09 09 73 sg += left;...s
20d0: 69 7a 65 20 2d 3d 20 6c 65 66 74 3b 0a 09 7d 0a ize -= left;..}.
20e0: 09 77 68 69 6c 65 20 28 73 69 7a 65 20 3e 3d 20 .while (size >=
20f0: 73 68 61 35 31 32 5f 62 6c 6f 63 6b 5f 73 69 7a sha512_block_siz
2100: 65 29 20 7b 0a 09 09 75 69 6e 74 36 34 5f 74 2a e) {...uint64_t*
2110: 20 61 6c 69 67 6e 65 64 5f 6d 65 73 73 61 67 65 aligned_message
2120: 5f 62 6c 6f 63 6b 3b 0a 09 09 69 66 20 28 49 53 _block;...if (IS
2130: 5f 41 4c 49 47 4e 45 44 5f 36 34 28 6d 73 67 29 _ALIGNED_64(msg)
2140: 29 20 7b 0a 09 09 09 2f 2a 20 74 68 65 20 6d 6f ) {..../* the mo
2150: 73 74 20 63 6f 6d 6d 6f 6e 20 63 61 73 65 20 69 st common case i
2160: 73 20 70 72 6f 63 65 73 73 69 6e 67 20 6f 66 20 s processing of
2170: 61 6e 20 61 6c 72 65 61 64 79 20 61 6c 69 67 6e an already align
2180: 65 64 20 6d 65 73 73 61 67 65 0a 09 09 09 77 69 ed message....wi
2190: 74 68 6f 75 74 20 63 6f 70 79 69 6e 67 20 69 74 thout copying it
21a0: 20 2a 2f 0a 09 09 09 61 6c 69 67 6e 65 64 5f 6d */....aligned_m
21b0: 65 73 73 61 67 65 5f 62 6c 6f 63 6b 20 3d 20 28 essage_block = (
21c0: 75 69 6e 74 36 34 5f 74 2a 29 6d 73 67 3b 0a 09 uint64_t*)msg;..
21d0: 09 7d 20 65 6c 73 65 20 7b 0a 09 09 09 6d 65 6d .} else {....mem
21e0: 63 70 79 28 63 74 78 2d 3e 6d 65 73 73 61 67 65 cpy(ctx->message
21f0: 2c 20 6d 73 67 2c 20 73 68 61 35 31 32 5f 62 6c , msg, sha512_bl
2200: 6f 63 6b 5f 73 69 7a 65 29 3b 0a 09 09 09 61 6c ock_size);....al
2210: 69 67 6e 65 64 5f 6d 65 73 73 61 67 65 5f 62 6c igned_message_bl
2220: 6f 63 6b 20 3d 20 63 74 78 2d 3e 6d 65 73 73 61 ock = ctx->messa
2230: 67 65 3b 0a 09 09 7d 0a 0a 09 09 72 68 61 73 68 ge;...}....rhash
2240: 5f 73 68 61 35 31 32 5f 70 72 6f 63 65 73 73 5f _sha512_process_
2250: 62 6c 6f 63 6b 28 63 74 78 2d 3e 68 61 73 68 2c block(ctx->hash,
2260: 20 61 6c 69 67 6e 65 64 5f 6d 65 73 73 61 67 65 aligned_message
2270: 5f 62 6c 6f 63 6b 29 3b 0a 09 09 6d 73 67 20 20 _block);...msg
2280: 2b 3d 20 73 68 61 35 31 32 5f 62 6c 6f 63 6b 5f += sha512_block_
2290: 73 69 7a 65 3b 0a 09 09 73 69 7a 65 20 2d 3d 20 size;...size -=
22a0: 73 68 61 35 31 32 5f 62 6c 6f 63 6b 5f 73 69 7a sha512_block_siz
22b0: 65 3b 0a 09 7d 0a 09 69 66 20 28 73 69 7a 65 29 e;..}..if (size)
22c0: 20 7b 0a 09 09 6d 65 6d 63 70 79 28 63 74 78 2d {...memcpy(ctx-
22d0: 3e 6d 65 73 73 61 67 65 2c 20 6d 73 67 2c 20 73 >message, msg, s
22e0: 69 7a 65 29 3b 20 2f 2a 20 73 61 76 65 20 6c 65 ize); /* save le
22f0: 66 74 6f 76 65 72 73 20 2a 2f 0a 09 7d 0a 7d 0a ftovers */..}.}.
2300: 0a 2f 2a 2a 0a 20 2a 20 53 74 6f 72 65 20 63 61 ./**. * Store ca
2310: 6c 63 75 6c 61 74 65 64 20 68 61 73 68 20 69 6e lculated hash in
2320: 74 6f 20 74 68 65 20 67 69 76 65 6e 20 61 72 72 to the given arr
2330: 61 79 2e 0a 20 2a 0a 20 2a 20 40 70 61 72 61 6d ay.. *. * @param
2340: 20 63 74 78 20 74 68 65 20 61 6c 67 6f 72 69 74 ctx the algorit
2350: 68 6d 20 63 6f 6e 74 65 78 74 20 63 6f 6e 74 61 hm context conta
2360: 69 6e 69 6e 67 20 63 75 72 72 65 6e 74 20 68 61 ining current ha
2370: 73 68 69 6e 67 20 73 74 61 74 65 0a 20 2a 20 40 shing state. * @
2380: 70 61 72 61 6d 20 72 65 73 75 6c 74 20 63 61 6c param result cal
2390: 63 75 6c 61 74 65 64 20 68 61 73 68 20 69 6e 20 culated hash in
23a0: 62 69 6e 61 72 79 20 66 6f 72 6d 0a 20 2a 2f 0a binary form. */.
23b0: 76 6f 69 64 20 72 68 61 73 68 5f 73 68 61 35 31 void rhash_sha51
23c0: 32 5f 66 69 6e 61 6c 28 73 68 61 35 31 32 5f 63 2_final(sha512_c
23d0: 74 78 20 2a 63 74 78 2c 20 75 6e 73 69 67 6e 65 tx *ctx, unsigne
23e0: 64 20 63 68 61 72 2a 20 72 65 73 75 6c 74 29 0a d char* result).
23f0: 7b 0a 09 73 69 7a 65 5f 74 20 69 6e 64 65 78 20 {..size_t index
2400: 3d 20 28 28 75 6e 73 69 67 6e 65 64 29 63 74 78 = ((unsigned)ctx
2410: 2d 3e 6c 65 6e 67 74 68 20 26 20 31 32 37 29 20 ->length & 127)
2420: 3e 3e 20 33 3b 0a 09 75 6e 73 69 67 6e 65 64 20 >> 3;..unsigned
2430: 73 68 69 66 74 20 3d 20 28 28 75 6e 73 69 67 6e shift = ((unsign
2440: 65 64 29 63 74 78 2d 3e 6c 65 6e 67 74 68 20 26 ed)ctx->length &
2450: 20 37 29 20 2a 20 38 3b 0a 0a 09 2f 2a 20 70 61 7) * 8;.../* pa
2460: 64 20 6d 65 73 73 61 67 65 20 61 6e 64 20 70 72 d message and pr
2470: 6f 63 65 73 73 20 74 68 65 20 6c 61 73 74 20 62 ocess the last b
2480: 6c 6f 63 6b 20 2a 2f 0a 0a 09 2f 2a 20 61 70 70 lock */.../* app
2490: 65 6e 64 20 74 68 65 20 62 79 74 65 20 30 78 38 end the byte 0x8
24a0: 30 20 74 6f 20 74 68 65 20 6d 65 73 73 61 67 65 0 to the message
24b0: 20 2a 2f 0a 09 63 74 78 2d 3e 6d 65 73 73 61 67 */..ctx->messag
24c0: 65 5b 69 6e 64 65 78 5d 20 20 20 26 3d 20 6c 65 e[index] &= le
24d0: 32 6d 65 5f 36 34 28 20 7e 28 49 36 34 28 30 78 2me_64( ~(I64(0x
24e0: 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 FFFFFFFFFFFFFFFF
24f0: 29 20 3c 3c 20 73 68 69 66 74 29 20 29 3b 0a 09 ) << shift) );..
2500: 63 74 78 2d 3e 6d 65 73 73 61 67 65 5b 69 6e 64 ctx->message[ind
2510: 65 78 2b 2b 5d 20 5e 3d 20 6c 65 32 6d 65 5f 36 ex++] ^= le2me_6
2520: 34 28 20 49 36 34 28 30 78 38 30 29 20 3c 3c 20 4( I64(0x80) <<
2530: 73 68 69 66 74 20 29 3b 0a 0a 09 2f 2a 20 69 66 shift );.../* if
2540: 20 6e 6f 20 72 6f 6f 6d 20 6c 65 66 74 20 69 6e no room left in
2550: 20 74 68 65 20 6d 65 73 73 61 67 65 20 74 6f 20 the message to
2560: 73 74 6f 72 65 20 31 32 38 2d 62 69 74 20 6d 65 store 128-bit me
2570: 73 73 61 67 65 20 6c 65 6e 67 74 68 20 2a 2f 0a ssage length */.
2580: 09 69 66 20 28 69 6e 64 65 78 20 3e 3d 20 31 35 .if (index >= 15
2590: 29 20 7b 0a 09 09 69 66 20 28 69 6e 64 65 78 20 ) {...if (index
25a0: 3d 3d 20 31 35 29 20 63 74 78 2d 3e 6d 65 73 73 == 15) ctx->mess
25b0: 61 67 65 5b 69 6e 64 65 78 5d 20 3d 20 30 3b 0a age[index] = 0;.
25c0: 09 09 72 68 61 73 68 5f 73 68 61 35 31 32 5f 70 ..rhash_sha512_p
25d0: 72 6f 63 65 73 73 5f 62 6c 6f 63 6b 28 63 74 78 rocess_block(ctx
25e0: 2d 3e 68 61 73 68 2c 20 63 74 78 2d 3e 6d 65 73 ->hash, ctx->mes
25f0: 73 61 67 65 29 3b 0a 09 09 69 6e 64 65 78 20 3d sage);...index =
2600: 20 30 3b 0a 09 7d 0a 09 77 68 69 6c 65 20 28 69 0;..}..while (i
2610: 6e 64 65 78 20 3c 20 31 35 29 20 7b 0a 09 09 63 ndex < 15) {...c
2620: 74 78 2d 3e 6d 65 73 73 61 67 65 5b 69 6e 64 65 tx->message[inde
2630: 78 2b 2b 5d 20 3d 20 30 3b 0a 09 7d 0a 09 63 74 x++] = 0;..}..ct
2640: 78 2d 3e 6d 65 73 73 61 67 65 5b 31 35 5d 20 3d x->message[15] =
2650: 20 62 65 32 6d 65 5f 36 34 28 63 74 78 2d 3e 6c be2me_64(ctx->l
2660: 65 6e 67 74 68 20 3c 3c 20 33 29 3b 0a 09 72 68 ength << 3);..rh
2670: 61 73 68 5f 73 68 61 35 31 32 5f 70 72 6f 63 65 ash_sha512_proce
2680: 73 73 5f 62 6c 6f 63 6b 28 63 74 78 2d 3e 68 61 ss_block(ctx->ha
2690: 73 68 2c 20 63 74 78 2d 3e 6d 65 73 73 61 67 65 sh, ctx->message
26a0: 29 3b 0a 0a 09 69 66 20 28 72 65 73 75 6c 74 29 );...if (result)
26b0: 20 62 65 36 34 5f 63 6f 70 79 28 72 65 73 75 6c be64_copy(resul
26c0: 74 2c 20 30 2c 20 63 74 78 2d 3e 68 61 73 68 2c t, 0, ctx->hash,
26d0: 20 63 74 78 2d 3e 64 69 67 65 73 74 5f 6c 65 6e ctx->digest_len
26e0: 67 74 68 29 3b 0a 7d 0a gth);.}.