Overview
Comment: | Added Cipher MAC (CMAC) support |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | crypto |
Files: | files | file ages | folders |
SHA3-256: |
49f76ba54c78b31e93eacea43c2c682c |
User & Date: | bohagan on 2023-11-10 20:09:23 |
Other Links: | branch diff | manifest | tags |
Context
2023-11-10
| ||
22:23 | Added cmac and hmac convenience commands check-in: 992cc75b71 user: bohagan tags: crypto | |
20:09 | Added Cipher MAC (CMAC) support check-in: 49f76ba54c user: bohagan tags: crypto | |
2023-11-08
| ||
03:09 | Updated test cases check-in: 9b69dccaca user: bohagan tags: crypto | |
Changes
Modified generic/tlsDigest.c from [ff147d0f8d] to [cd70ba2139].
︙ | |||
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | + + + + + - + + | #include "tlsInt.h" #include "tclOpts.h" #include <tcl.h> #include <stdio.h> #include <string.h> #include <openssl/evp.h> #include <openssl/cmac.h> #include <openssl/hmac.h> /* Constants */ const char *hex = "0123456789ABCDEF"; /* Macros */ #define BUFFER_SIZE 65536 #define BIN_FORMAT 0 #define HEX_FORMAT 1 #define CHAN_EOF 0x10 #define TYPE_MD 0x20 #define TYPE_HMAC 0x40 #define TYPE_CMAC 0x80 /* * 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 */ int flags; /* Chan config flags */ int watchMask; /* Current WatchProc mask */ int mode; /* Current mode of parent channel */ |
︙ | |||
63 64 65 66 67 68 69 | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | - + + + | if (statePtr != NULL) { memset(statePtr, 0, sizeof(DigestState)); statePtr->self = NULL; /* This socket channel */ statePtr->timer = NULL; /* Timer to flush data */ statePtr->flags = 0; /* Chan config flags */ statePtr->watchMask = 0; /* Current WatchProc mask */ statePtr->mode = 0; /* Current mode of parent channel */ |
︙ | |||
97 98 99 100 101 102 103 104 105 106 107 108 109 110 | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | + + + | if (statePtr->ctx != (EVP_MD_CTX *) NULL) { EVP_MD_CTX_free(statePtr->ctx); } if (statePtr->hctx != (HMAC_CTX *) NULL) { HMAC_CTX_free(statePtr->hctx); } if (statePtr->cctx != (CMAC_CTX *) NULL) { CMAC_CTX_free(statePtr->cctx); } ckfree(statePtr); } /*******************************************************************/ /* *------------------------------------------------------------------- |
︙ | |||
119 120 121 122 123 124 125 | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | - - + + - + - + + + + - + - + + + + | * * Side effects: * No result or error message * *------------------------------------------------------------------- */ int Tls_DigestInit(Tcl_Interp *interp, DigestState *statePtr, const EVP_MD *md, |
︙ | |||
166 167 168 169 170 171 172 | 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | - + - + - + + + | * * Side effects: * Adds buf to hash function * *------------------------------------------------------------------- */ int Tls_DigestUpdate(DigestState *statePtr, char *buf, size_t read) { |
︙ | |||
196 197 198 199 200 201 202 | 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | - + - + - + + + + + - + - - - + + | * *------------------------------------------------------------------- */ int Tls_DigestFinialize(Tcl_Interp *interp, DigestState *statePtr) { unsigned char md_buf[EVP_MAX_MD_SIZE]; unsigned int md_len; |
︙ | |||
270 271 272 273 274 275 276 | 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | - + | /* Create state data struct */ if ((statePtr = Tls_DigestNew(interp, format)) == NULL) { res = TCL_ERROR; goto done; } /* Initialize hash function */ |
︙ | |||
393 394 395 396 397 398 399 | 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | - + | * Read data from transform and write to buf * *---------------------------------------------------------------------- */ int DigestInputProc(ClientData clientData, char *buf, int toRead, int *errorCodePtr) { DigestState *statePtr = (DigestState *) clientData; Tcl_Channel parent; |
︙ | |||
426 427 428 429 430 431 432 | 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | - + - + + + + + - + - + | } else if (!(statePtr->flags & CHAN_EOF)) { /* EOF */ unsigned char md_buf[EVP_MAX_MD_SIZE]; unsigned int md_len = 0; /* Finalize hash function and calculate message digest */ |
︙ | |||
747 748 749 750 751 752 753 | 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 | - - + + - + | * * Side effects: * Adds transform to channel and sets result to channel id or error message. * *---------------------------------------------------------------------- */ static int |
︙ | |||
776 777 778 779 780 781 782 | 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 | - + | Tcl_AppendResult(interp, "Initialize digest error: memory allocation failure", (char *) NULL); return TCL_ERROR; } statePtr->self = chan; statePtr->mode = mode; /* Initialize hash function */ |
︙ | |||
948 949 950 951 952 953 954 | 974 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 | - - + + - + | * TCL_OK or TCL_ERROR * * Side effects: * Creates command or error message * *------------------------------------------------------------------- */ |
︙ | |||
993 994 995 996 997 998 999 | 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 | - + | * Side effects: * Sets result to message digest or error message * *------------------------------------------------------------------- */ int Tls_DigestData(Tcl_Interp *interp, int objc, Tcl_Obj *const objv[], |
︙ | |||
1027 1028 1029 1030 1031 1032 1033 | 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 | - + | hmac = HMAC(md, (const void *) key, key_len, (const unsigned char *) data, (size_t) len, md_buf, &md_len); res = (hmac != NULL); } /* Output digest to result per format (bin or hex) */ if (res) { |
︙ | |||
1068 1069 1070 1071 1072 1073 1074 | 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 | - + + + - - + + - + - - + + + - + + + + + + + + + + + + + + + + + + + - + - + - + - + + + + + + + + + - + - + - + - + - + + + | * Side effects: * Sets result to message digest or error message * *------------------------------------------------------------------- */ static int DigestObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { |
Modified generic/tlsInfo.c from [9aada2ce3d] to [bed510f6e3].
︙ | |||
68 69 70 71 72 73 74 75 76 77 78 79 80 81 | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | + | *------------------------------------------------------------------- */ static int CiphersObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { SSL_CTX *ctx = NULL; SSL *ssl = NULL; STACK_OF(SSL_CIPHER) *sk = NULL; int index, verbose = 0, use_supported = 0; int min_version, max_version; dprintf("Called"); #if OPENSSL_VERSION_NUMBER < 0x10100000L OpenSSL_add_all_ciphers(); /* Make sure they're loaded */ #endif |
︙ |