Index: doc/tls.html
==================================================================
--- doc/tls.html
+++ doc/tls.html
@@ -34,10 +34,11 @@
tls::ciphers protocol ?verbose? ?supported?
tls::protocols
tls::version
tls::hash type data
+ tls::hashes
tls::md4 data
tls::md5 data
tls::sha1 data
tls::sha256 data
@@ -73,10 +74,11 @@
tls::ciphers protocol ?verbose? ?supported?
tls::protocols
tls::version
tls::hash type data
+tls::hashes
tls::md4 data
tls::md5 data
tls::sha1 data
tls::sha256 data
@@ -451,10 +453,13 @@
Returns value as a hex string. Type cam be any OpenSSL supported
hash digest including: md4, md5, sha1,
sha2 (sha224, sha256, sha384, sha512,
sha512-224, and sha512-256),
sha3 (sha3-224, sha3-256, sha3-384, and sha3-512), etc.
+
+ tls::hashes
+ Returns a list of the valid hash digests.
tls::md4 data
Calculate the hash for data using the MD4 message-digest algorithm.
tls::md5 data
Index: generic/tls.c
==================================================================
--- generic/tls.c
+++ generic/tls.c
@@ -976,11 +976,11 @@
}
/*
*-------------------------------------------------------------------
*
- * Hash Commands -- Return hash hex string for message digest
+ * Hash Commands -- Return hash value for digest as hex string
*
* Results:
* A standard Tcl result.
*
* Side effects:
@@ -1037,10 +1037,47 @@
*/
int
HashSHA256Cmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) {
return HashCalc(interp, objc, objv, EVP_sha256());
}
+
+/*
+ *-------------------------------------------------------------------
+ *
+ * Hash List Command -- Return list of hash message digests
+ *
+ * Results:
+ * A standard Tcl result.
+ *
+ * Side effects:
+ * None.
+ *
+ *-------------------------------------------------------------------
+ */
+
+void HashListCallback(const OBJ_NAME *obj, void *arg) {
+ Tcl_Obj *objPtr = (Tcl_Obj *) arg;
+ Tcl_ListObjAppendElement(NULL, objPtr, Tcl_NewStringObj(obj->name,-1));
+}
+
+/*
+ * Command to list available Hash values
+ */
+int
+HashListCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) {
+ Tcl_Obj *objPtr = Tcl_NewListObj(0, NULL);
+
+ OpenSSL_add_all_digests(); //make sure they're loaded
+ OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, HashListCallback, (void *) objPtr);
+ Tcl_ResetResult(interp);
+ Tcl_SetObjResult(interp, objPtr);
+
+ return TCL_OK;
+ clientData = clientData;
+ objc = objc;
+ objv = objv;
+}
/*
*-------------------------------------------------------------------
*
* CiphersObjCmd -- list available ciphers
@@ -2898,10 +2935,11 @@
Tcl_CreateObjCommand(interp, "tls::version", VersionObjCmd, (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp, "tls::misc", MiscObjCmd, (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp, "tls::protocols", ProtocolsObjCmd, (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp, "tls::hash", HashCmd, (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
+ Tcl_CreateObjCommand(interp, "tls::hashes", HashListCmd, (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp, "tls::md4", HashMD4Cmd, (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp, "tls::md5", HashMD5Cmd, (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp, "tls::sha1", HashSHA1Cmd, (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp, "tls::sha256", HashSHA256Cmd, (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);