Files
calc/help/sha
2017-05-21 15:38:45 -07:00

127 lines
3.6 KiB
Plaintext

NAME
sha - old Secure Hash Algorithm (SHS FIPS Pub 180)
SYNOPSIS
sha([arg1 [, val ...]])
TYPES
arg1 any
val any
return HASH or number
DESCRIPTION
The sha() builtin implements the old Secure Hash Algorithm
(SHA). The SHA is sometimes referenced as SHS. The SHA
is a 160 bit hash.
With no args, sha() returns the default initial SHA-1 HASH state.
If arg1 is a HASH state and no other val args are given, then the
HASH state is finalized and the numeric value of the hash is given.
If arg1 is a HASH state and one or more val args are given,
then the val args are used to modify the arg1 HASH state.
The new arg1 HASH state is returned.
If arg1 is not a a HASH state, then the initial HASH is
used and modifed by arg1 and any val args supplied. The
return value is the new HASH state.
The following table gives a summary of actions and return values.
Here, assume that 'h' is a HASH state:
sha() HASH returns initial HASH state
sha(h) number h is put into final form and the
numeric value of the hash state
sha(x) HASH modify the initial state by hashing 'x'
sha(sha(), x) HASH the same as sha(x)
sha(x, y) HASH the same as sha(sha(x), y)
sha(h, x, y) HASH modify state 'h' by 'x' and then 'y'
sha(sha(h,x,y)) number numeric value of the above call
EXAMPLE
; base(16)
0xa
; sha()
sha hash state
; sha(sha())
0xf96cea198ad1dd5617ac084a3d92c6107708c0ef
; sha("x", "y", "z") == sha("xyz")
1
; sha("x", "y", "z") == sha("xy")
0
; sha(sha("this is", 7^19-8, "a composit", 3i+4.5, "hash"))
0x21e42319a26787046c2b28b7ae70f1b54bf0ba2a
; x = sha(list(1,2,3), "curds and whey", 2^21701-1, pi())
; x
sha hash state
; sha(x)
0xc9e155522ea4a38d85340e6f1c2e36636950ea7e
; y = sha()
; y = sha(y, list(1,2,3), "curds and whey")
; y = sha(y, 2^21701-1)
; y = sha(y, pi())
; y
sha hash state
; sha(y)
0xc9e155522ea4a38d85340e6f1c2e36636950ea7e
LIMITS
none
LINK LIBRARY
HASH* hash_init(int, HASH*);
void hash_free(HASH*);
HASH* hash_copy(HASH*);
int hash_cmp(HASH*, HASH*);
void hash_print(HASH*);
ZVALUE hash_final(HASH*);
HASH* hash_long(int, long, HASH*);
HASH* hash_zvalue(int, ZVALUE, HASH*);
HASH* hash_number(int, void*, HASH*);
HASH* hash_complex(int, void*, HASH*);
HASH* hash_str(int, char*, HASH*);
HASH* hash_usb8(int, USB8*, int, HASH*);
HASH* hash_value(int, void*, HASH*);
SEE ALSO
ishash, sha1
## Copyright (C) 1999 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License
## as published by the Free Software Foundation.
##
## Calc is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
## Public License for more details.
##
## A copy of version 2.1 of the GNU Lesser General Public License is
## distributed with calc under the filename COPYING-LGPL. You should have
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.3 $
## @(#) $Id: sha,v 29.3 2006/05/07 07:25:46 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sha,v $
##
## Under source code control: 1997/03/22 06:25:51
## File existed as early as: 1997
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/