Reviewed and revised April 2024
xcall DIGEST, digtype, srcdata, bytes, digest, status
DIGEST 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. See comments below.
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 srcdata is type S, bytes may be set to 0 to mean the logical string length. If -1, srcdata is interpreted as the name of the file to process.
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-256 |
X,32 or S,64 |
Note: for applications requiring the digest encoded in base64, you can use CRYPTO to perform the conversion.
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
DIGEST and HASH 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.
See Also
• | CRYPTO for HMAC (key encrypted) versions of the SHA and MD digests, as well as hex/base64 conversions. |
• | DIGEST in EXLIB:[908,55] for example of usage. |
• | HASH |
History
2013 May, A-Shell 6.1.1353: Routine added to A-Shell