Initial revision
[LeanCalc.git] / help / sha
1 NAME
2     sha - old Secure Hash Algorithm (SHS FIPS Pub 180)
3
4 SYNOPSIS
5     sha([arg1 [, val ...]])
6
7 TYPES
8     arg1        any
9     val         any
10
11     return      HASH or number
12
13 DESCRIPTION
14     The sha() builtin implements the old Secure Hash Algorithm
15     (SHA).  The SHA is sometimes referenced as SHS.  The SHA
16     is a 160 bit hash.
17
18     With no args, sha() returns the default initial SHA-1 HASH state.
19
20     If arg1 is a HASH state and no other val args are given, then the
21     HASH state is finalized and the numeric value of the hash is given.
22
23     If arg1 is a HASH state and one or more val args are given,
24     then the val args are used to modify the arg1 HASH state.
25     The new arg1 HASH state is returned.
26
27     If arg1 is not a a HASH state, then the initial HASH is
28     used and modifed by arg1 and any val args supplied.  The
29     return value is the new HASH state.
30
31     The following table gives a summary of actions and return values.
32     Here, assume that 'h' is a HASH state:
33
34         sha()                   HASH    returns initial HASH state
35
36         sha(h)                  number  h is put into final form and the
37                                         numeric value of the hash state
38
39         sha(x)                  HASH    modify the initial state by hashing 'x'
40
41         sha(sha(), x)           HASH    the same as sha(x)
42
43         sha(x, y)               HASH    the same as sha(sha(x), y)
44
45         sha(h, x, y)            HASH    modify state 'h' by 'x' and then 'y'
46
47         sha(sha(h,x,y))         number  numeric value of the above call
48
49 EXAMPLE
50     > base(16)
51             0xa
52
53     > sha()
54             sha hash state
55     > sha(sha())
56             0xf96cea198ad1dd5617ac084a3d92c6107708c0ef
57
58     > sha("x", "y", "z") == sha("xyz")
59             1
60     > sha("x", "y", "z") == sha("xy")
61             0
62
63     > sha(sha("this is", 7^19-8, "a composit", 3i+4.5, "hash"))
64             0x21e42319a26787046c2b28b7ae70f1b54bf0ba2a
65
66     > x = sha(list(1,2,3), "curds and whey", 2^21701-1, pi())
67     > x
68             sha hash state
69     > sha(x)
70             0xc9e155522ea4a38d85340e6f1c2e36636950ea7e
71
72     > y = sha()
73     > y = sha(y, list(1,2,3), "curds and whey")
74     > y = sha(y, 2^21701-1)
75     > y = sha(y, pi())
76     > y
77             sha hash state
78     > sha(y)
79             0xc9e155522ea4a38d85340e6f1c2e36636950ea7e
80
81 LIMITS
82     none
83
84 LINK LIBRARY
85     HASH* hash_init(int, HASH*);
86     void hash_free(HASH*);
87     HASH* hash_copy(HASH*);
88     int hash_cmp(HASH*, HASH*);
89     void hash_print(HASH*);
90     ZVALUE hash_final(HASH*);
91     HASH* hash_long(int, long, HASH*);
92     HASH* hash_zvalue(int, ZVALUE, HASH*);
93     HASH* hash_number(int, void*, HASH*);
94     HASH* hash_complex(int, void*, HASH*);
95     HASH* hash_str(int, char*, HASH*);
96     HASH* hash_usb8(int, USB8*, int, HASH*);
97     HASH* hash_value(int, void*, HASH*);
98
99 SEE ALSO
100     ishash, sha1
101