Overview
Comment: | Split get digest, cipher, key, and mac ids into separate functions. Simplified DigestMain to pass Tcl objects to get functions. Pass mac id to functions. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | crypto |
Files: | files | file ages | folders |
SHA3-256: |
0aae4d5b6f248afb36cf5bbc2941b625 |
User & Date: | bohagan on 2023-11-25 05:23:07 |
Other Links: | branch diff | manifest | tags |
Context
2023-11-26
| ||
02:15 | Split doc file into TLS and cryptography files. Moved digest functions to cryptography.html doc file. Added schema file from TCL man pages. Updated TLS doc file. check-in: b5b7a4964e user: bohagan tags: crypto | |
2023-11-25
| ||
05:23 | Split get digest, cipher, key, and mac ids into separate functions. Simplified DigestMain to pass Tcl objects to get functions. Pass mac id to functions. check-in: 0aae4d5b6f user: bohagan tags: crypto | |
2023-11-23
| ||
04:17 | Added more test cases to check for errors, test mac command, etc. check-in: 4ba41f1db2 user: bohagan tags: crypto | |
Changes
Modified generic/tlsDigest.c from [4e866a5357] to [83013db897].
︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | + + + + | #define HEX_FORMAT 0x02 #define IS_XOF 0x08 #define TYPE_MD 0x10 #define TYPE_HMAC 0x20 #define TYPE_CMAC 0x40 #define TYPE_MAC 0x80 #if OPENSSL_VERSION_NUMBER <= 0x30000000L #define EVP_MAC void #endif /* * This structure defines the per-instance state of a digest operation. */ typedef struct DigestState { Tcl_Channel self; /* This socket channel */ Tcl_TimerToken timer; /* Timer for read events */ |
︙ | |||
142 143 144 145 146 147 148 | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | - + | * * Side effects: * No result or error message * *------------------------------------------------------------------- */ int DigestInitialize(Tcl_Interp *interp, DigestState *statePtr, const EVP_MD *md, |
︙ | |||
729 730 731 732 733 734 735 | 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 | - + | * Side effects: * Adds transform to channel and sets result to channel id or error message. * *---------------------------------------------------------------------- */ static int DigestChannelHandler(Tcl_Interp *interp, const char *channel, const EVP_MD *md, |
︙ | |||
757 758 759 760 761 762 763 | 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 | - + | Tcl_AppendResult(interp, "Memory allocation error", (char *) NULL); return TCL_ERROR; } statePtr->self = chan; statePtr->mode = mode; /* Initialize hash function */ |
︙ | |||
802 803 804 805 806 807 808 | 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 | - + | static int DigestUnstackObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { Tcl_Channel chan; int mode; /* OR-ed combination of TCL_READABLE and TCL_WRITABLE */ /* Validate arg count */ if (objc != 2) { |
︙ | |||
830 831 832 833 834 835 836 | 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 | - - + | /* Pop transform from channel */ return Tcl_UnstackChannel(interp, chan); clientData = clientData; } /*******************************************************************/ |
︙ | |||
928 929 930 931 932 933 934 | 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 | - + - + | * * Side effects: * Creates command or error message * *------------------------------------------------------------------- */ int DigestCommandHandler(Tcl_Interp *interp, Tcl_Obj *cmdObj, const EVP_MD *md, |
︙ | |||
972 973 974 975 976 977 978 | 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 | - + - + | * Side effects: * Sets result to message digest or error message * *------------------------------------------------------------------- */ int DigestDataHandler(Tcl_Interp *interp, Tcl_Obj *dataObj, const EVP_MD *md, |
︙ | |||
1021 1022 1023 1024 1025 1026 1027 | 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 | - + | * * Side effects: * Result is message digest or error message * *------------------------------------------------------------------- */ int DigestFileHandler(Tcl_Interp *interp, Tcl_Obj *filename, const EVP_MD *md, |
︙ | |||
1047 1048 1049 1050 1051 1052 1053 | 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 | - + | /* Configure channel */ if ((res = Tcl_SetChannelOption(interp, chan, "-translation", "binary")) == TCL_ERROR) { goto done; } Tcl_SetChannelBufferSize(chan, BUFFER_SIZE); /* Initialize hash function */ |
︙ | |||
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 | 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + - + - + - + - + - + - + - + - - - + - - - + - - + - - - - - + + - - + - - + - - - - - + - + - + - + | } /*******************************************************************/ /* *------------------------------------------------------------------- * * GetDigest -- Get message digest * * Returns: * EVP_MD * or NULL * *------------------------------------------------------------------- */ EVP_MD *GetDigest(Tcl_Interp *interp, Tcl_Obj *objPtr, int *format) { const EVP_MD *md = NULL; char *digestName = Tcl_GetStringFromObj(objPtr, NULL); if (digestName != NULL) { md = EVP_get_digestbyname(digestName); if (md == NULL) { Tcl_AppendResult(interp, "Invalid digest \"", digestName, "\"", NULL); return NULL; } else if (md == EVP_shake128() || md == EVP_shake256()) { *format |= IS_XOF; } } else { Tcl_AppendResult(interp, "No digest specified", NULL); return NULL; } return md; } /* *------------------------------------------------------------------- * * GetCipher -- Get cipher * * Returns: * EVP_CIPHER * or NULL * *------------------------------------------------------------------- */ EVP_CIPHER *GetCipher(Tcl_Interp *interp, Tcl_Obj *objPtr, int *type) { const EVP_CIPHER *cipher = NULL; char *cipherName = Tcl_GetStringFromObj(objPtr, NULL); if (cipherName != NULL) { cipher = EVP_get_cipherbyname(cipherName); *type = TYPE_CMAC; if (cipher == NULL) { Tcl_AppendResult(interp, "Invalid cipher \"", cipherName, "\"", NULL); return NULL; } } else { Tcl_AppendResult(interp, "No cipher specified", NULL); return NULL; } return cipher; } /* *------------------------------------------------------------------- * * GetKey -- Get key * * Returns: * unsigned char * or NULL * *------------------------------------------------------------------- */ unsigned char *GetKey(Tcl_Interp *interp, Tcl_Obj *objPtr, int *type) { unsigned char *key = Tcl_GetByteArrayFromObj(objPtr, NULL); if (key == NULL) { Tcl_AppendResult(interp, "No key specified", NULL); return NULL; } if (*type == TYPE_MD) { *type = TYPE_HMAC; } return key; } /* *------------------------------------------------------------------- * * GetMAC -- Get MAC * * Returns: * EVP_MAC * or NULL * *------------------------------------------------------------------- */ EVP_MAC *GetMAC(Tcl_Interp *interp, Tcl_Obj *objPtr, int *type) { EVP_MAC *mac = NULL; char *macName = Tcl_GetStringFromObj(objPtr, NULL); if (macName != NULL) { if (strcmp(macName, "cmac") == 0) { *type = TYPE_CMAC; } else if (strcmp(macName, "hmac") == 0) { *type = TYPE_HMAC; } else { Tcl_AppendResult(interp, "Invalid MAC \"", macName, "\"", NULL); return NULL; } mac = (void *) macName; } else { Tcl_AppendResult(interp, "No MAC specified", NULL); return NULL; } return mac; } /*******************************************************************/ /* *------------------------------------------------------------------- * * DigestMain -- * * Return message digest or Message Authentication Code (MAC) of * data using user specified hash function. * * Returns: * TCL_OK or TCL_ERROR * * Side effects: * Sets result to message digest or error message * *------------------------------------------------------------------- */ static int DigestMain(int type, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { int idx, start = 1, format = HEX_FORMAT, res = TCL_OK; Tcl_Obj *cipherObj = NULL, *cmdObj = NULL, *dataObj = NULL, *digestObj = NULL; |
︙ | |||
1282 1283 1284 1285 1286 1287 1288 | 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 | - + - + - + - + - + | Tcl_WrongNumArgs(interp, 1, objv, "data"); \ return TCL_ERROR; \ } \ } int MD4ObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { validate_argc(objc, objv); |
︙ |