xcall DIGEST, digtype, srcdata, bytes, digest, status
DIGEST.SBR returns various cryptographic digests of strings or files.
Parameters
digtype (num) [in]
indicates the type of digest desired:
Value |
Type |
Digest Length in Bits |
---|---|---|
3 |
MD5 |
128 |
4 |
SHA 1 |
160 |
5 |
SHA 256 |
256 |
Note that the DIGTYPE values start at 3 rather than 1 to avoid possible conflict/confusion with the very similar HASH.SBR. See comments below.
srcdata (S or X) [in]
data to get the digest of. If bytes=-1, then this is interpreted as the filespec (AMOS or native) containing the data.
bytes (num) [in]
number of bytes to process. If 0, we process up to the first null byte. If -1, srcdata is interpreted as the name of the file to process.
digest (X or S) [out]
returned digest. If X, the digest is returned in raw binary form. If S, it is returned in hex representation. Minimum sizes depend on the digtype:
Value |
Type |
---|---|
MD5 |
X,16 or S,32 |
SHA-1 |
X,20 or S,40 |
SHA-5 |
X,32 or S,64 |
status (signed num) [out]
returns status indicator:
Value |
Meaning |
---|---|
>=0 |
# of bytes processed; should match bytes |
-1 |
bad data type for srcdata |
-2 |
bad digtype |
-3 |
bad digest type or size |
-4 |
file not found |
Comments
See SOBLIB program DIGEST.BP for example of usage.
DIGEST.SBR and HASH.SBR are very similar and may eventually be merged, although at present only DIGEST supports the file option. HASH is more oriented towards maximum performance with relatively small keys, as might be useful in a hash table alternative to a traditional index. DIGEST is more oriented towards security applications and large keys (or files) where computational performance and compactness are less important than minimizing the possibility of different keys having the same digest.