# DIGEST
> [HTML Version](digestsbr.htm)
_Reviewed and revised April 2024_
**xcall DIGEST, digtype, srcdata, bytes, digest, status**
DIGEST returns various cryptographic digests of strings or files.
**Parameters**
_digtype_ ([Num](num.htm.md)) \[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](hashsbr.htm.md). See comments below.
_srcdata _ ([String](string.htm.md) or [BLOB](blob.htm.md)) \[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](num.htm.md)) \[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.
_digest _ ([String](string.htm.md) or [BLOB](blob.htm.md)) \[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-256 | X,32 or S,64 |
Note: for applications requiring the digest encoded in base64, you can use [CRYPTO](cryptosbr.htm.md)[xs](get_sbr.htm.md) to perform the conversion.
_status_ (Signed [Num](num.htm.md)) \[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](hashsbr.htm.md)[xs](get_sbr.htm.md) 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](cryptosbr.htm.md)[xs](get_sbr.htm.md) for HMAC (key encrypted) versions of the SHA and MD [xs](get_sbr.htm.md), as well as hex/base64 conversions.
• [DIGEST in EXLIB:\[908,55\]](https://bitbucket.org/microsabio/exlib/src/master/908055/digest.bp) for example of usage.
• [MX\_HASHFILE](mx_hashfile.htm.md)[xs](get_sbr.htm.md) to get file hash total
• [HASH](hashsbr.htm.md)[xs](get_sbr.htm.md)
**History**
2013 May, A-Shell 6.1.1353: Routine added to A-Shell