Overview
Comment: | Added more comments and removed obsolete code |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | crypto |
Files: | files | file ages | folders |
SHA3-256: |
5a0296430f5b1cf214d2a048983e1d7e |
User & Date: | bohagan on 2023-11-06 23:46:34 |
Other Links: | branch diff | manifest | tags |
Context
2023-11-07
| ||
23:40 | Optimized info commands and added more error checking. Use modern set protocol versions API for ciphers list. check-in: e88816cf57 user: bohagan tags: crypto | |
2023-11-06
| ||
23:46 | Added more comments and removed obsolete code check-in: 5a0296430f user: bohagan tags: crypto | |
04:52 | Added an option to the digest command to allow the user to create a new command, use it to add data to a hash, and to get the final message digest. Refactored code to move common digest init, update, and finalize operations into common functions. check-in: 0c59081d81 user: bohagan tags: crypto | |
Changes
Modified generic/tlsDigest.c
from [7c8820a0b3]
to [ff147d0f8d].
1 2 3 | 1 2 3 4 5 6 7 8 9 10 11 | - + | /* * Message Digests Module * |
︙ | |||
20 21 22 23 24 25 26 | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | - + - - | /* Macros */ #define BUFFER_SIZE 65536 #define BIN_FORMAT 0 #define HEX_FORMAT 1 #define CHAN_EOF 0x10 /* |
︙ | |||
55 56 57 58 59 60 61 | 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | - + | * * Side effects: * Creates structure * *------------------------------------------------------------------- */ DigestState *Tls_DigestNew(Tcl_Interp *interp, int format) { |
︙ | |||
89 90 91 92 93 94 95 | 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | - + + + | * * Side effects: * Removes structure * *------------------------------------------------------------------- */ void Tls_DigestFree(DigestState *statePtr) { |
︙ | |||
258 259 260 261 262 263 264 | 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | - + - - + | /* Open file channel */ chan = Tcl_FSOpenFileChannel(interp, filename, "rb", 0444); if (chan == (Tcl_Channel) NULL) { return TCL_ERROR; } /* Configure channel */ |
︙ | |||
293 294 295 296 297 298 299 | 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | - - | /* Finalize hash function and calculate message digest */ res = Tls_DigestFinialize(interp, statePtr); done: /* Close channel */ if (Tcl_Close(interp, chan) == TCL_ERROR) { |
︙ | |||
347 348 349 350 351 352 353 | 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | - + | * queued output is flushed prior to calling this function. * * Returns: * 0 if successful or POSIX error code if failed. * * Side effects: * Writes digest to output and closes the channel. Stores error |
︙ | |||
399 400 401 402 403 404 405 406 407 408 409 410 411 412 | 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | + | */ int DigestInputProc(ClientData clientData, char *buf, int toRead, int *errorCodePtr) { DigestState *statePtr = (DigestState *) clientData; Tcl_Channel parent; int read, res; *errorCodePtr = 0; /* Abort if nothing to process */ if (toRead <= 0 || statePtr->self == (Tcl_Channel) NULL) { return 0; } /* Get bytes from underlying channel */ parent = Tcl_GetStackedChannel(statePtr->self); read = Tcl_ReadRaw(parent, buf, toRead); |
︙ | |||
424 425 426 427 428 429 430 | 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | - + | } else if (read < 0) { /* Error */ *errorCodePtr = Tcl_GetErrno(); } else if (!(statePtr->flags & CHAN_EOF)) { /* EOF */ |
︙ | |||
480 481 482 483 484 485 486 487 488 489 490 491 492 493 | 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | + | * *---------------------------------------------------------------------- */ int DigestOutputProc(ClientData clientData, const char *buf, int toWrite, int *errorCodePtr) { DigestState *statePtr = (DigestState *) clientData; *errorCodePtr = 0; /* Abort if nothing to process */ if (toWrite <= 0 || statePtr->self == (Tcl_Channel) NULL) { return 0; } /* Update hash function */ if (toWrite > 0 && !Tls_DigestUpdate(statePtr, buf, (size_t) toWrite)) { Tcl_SetChannelError(statePtr->self, Tcl_ObjPrintf("Digest update failed: %s", REASON())); |
︙ | |||
515 516 517 518 519 520 521 522 523 524 525 526 527 528 | 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 | + | */ static int DigestSetOptionProc(ClientData clientData, Tcl_Interp *interp, const char *optionName, const char *optionValue) { DigestState *statePtr = (DigestState *) clientData; Tcl_Channel parent; Tcl_DriverSetOptionProc *setOptionProc; /* Abort if no channel */ if (statePtr->self == (Tcl_Channel) NULL) { return TCL_ERROR; } /* Delegate options downstream */ parent = Tcl_GetStackedChannel(statePtr->self); setOptionProc = Tcl_ChannelSetOptionProc(Tcl_GetChannelType(parent)); |
︙ | |||
552 553 554 555 556 557 558 559 560 561 562 563 564 565 | 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | + | */ static int DigestGetOptionProc(ClientData clientData, Tcl_Interp *interp, const char *optionName, Tcl_DString *optionValue) { DigestState *statePtr = (DigestState *) clientData; Tcl_Channel parent; Tcl_DriverGetOptionProc *getOptionProc; /* Abort if no channel */ if (statePtr->self == (Tcl_Channel) NULL) { return TCL_ERROR; } /* Delegate options downstream */ parent = Tcl_GetStackedChannel(statePtr->self); getOptionProc = Tcl_ChannelGetOptionProc(Tcl_GetChannelType(parent)); |
︙ | |||
588 589 590 591 592 593 594 595 596 597 598 599 600 601 | 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | + | * May call Tcl_NotifyChannel * *---------------------------------------------------------------------- */ static void DigestTimerHandler(ClientData clientData) { DigestState *statePtr = (DigestState *) clientData; /* Abort if no channel */ if (statePtr->self == (Tcl_Channel) NULL) { return; } /* Clear timer token */ statePtr->timer = (Tcl_TimerToken) NULL; |
︙ | |||
609 610 611 612 613 614 615 | 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | - + + | *---------------------------------------------------------------------- * * DigestWatchProc -- * * Initialize the notifier to watch for events from this channel. * * Returns: |
︙ | |||
666 667 668 669 670 671 672 673 674 675 676 | 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 | + + + - + + | * Side effects: * None * *---------------------------------------------------------------------- */ int DigestGetHandleProc(ClientData clientData, int direction, ClientData *handlePtr) { DigestState *statePtr = (DigestState *) clientData; Tcl_Channel parent; /* Abort if no channel */ if (statePtr->self == (Tcl_Channel) NULL) { return TCL_ERROR; } |
︙ | |||
735 736 737 738 739 740 741 | 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 | - + - - + - + | * * Create a stacked channel for a message digest transformation. * * Returns: * TCL_OK or TCL_ERROR * * Side effects: |
︙ | |||
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 | 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 | + - - + + + | /* Stack channel */ statePtr->self = Tcl_StackChannel(interp, &digestChannelType, (ClientData) statePtr, mode, chan); if (statePtr->self == (Tcl_Channel) NULL) { Tls_DigestFree(statePtr); return TCL_ERROR; } /* Set result to channel Id */ Tcl_SetResult(interp, (char *) Tcl_GetChannelName(chan), TCL_VOLATILE); return TCL_OK; } /* *---------------------------------------------------------------------- * * Unstack Channel -- * |
︙ | |||
834 835 836 837 838 839 840 | 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 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 | - - + + - - - - + + + - + - + + | if (Tcl_GetChannelType(chan) != &digestChannelType) { Tcl_AppendResult(interp, "bad channel \"", Tcl_GetChannelName(chan), "\": not a digest channel", NULL); Tcl_SetErrorCode(interp, "TLS", "UNSTACK", "CHANNEL", "INVALID", (char *) NULL); return TCL_ERROR; } |
︙ | |||
945 946 947 948 949 950 951 | 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 | - + | *------------------------------------------------------------------- */ int Tls_DigestInstance(Tcl_Interp *interp, Tcl_Obj *cmdObj, const EVP_MD *md, int format, Tcl_Obj *keyObj) { DigestState *statePtr; char *cmdName = Tcl_GetStringFromObj(cmdObj, NULL); |
︙ | |||
973 974 975 976 977 978 979 | 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 1009 1010 1011 1012 1013 | - + + | /*******************************************************************/ /* *------------------------------------------------------------------- * * Tls_DigestData -- * |
︙ | |||
1059 1060 1061 1062 1063 1064 1065 | 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 | - + - + + | * Side effects: * Sets result to message digest or error message * *------------------------------------------------------------------- */ static int DigestObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { |
︙ | |||
1088 1089 1090 1091 1092 1093 1094 | 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 | - + + - + - + | return Tls_DigestData(interp, --objc, ++objv, md, format, NULL); } /* Get options */ for (idx = 2; idx < objc-1; idx++) { char *opt = Tcl_GetStringFromObj(objv[idx], NULL); |
︙ |
Modified generic/tlsInfo.c
from [9b024f9b80]
to [1f24eba4d4].
︙ | |||
37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | + + | * Side effects: * None. * *------------------------------------------------------------------- */ void NamesCallback(const OBJ_NAME *obj, void *arg) { Tcl_Obj *objPtr = (Tcl_Obj *) arg; /* Fields: (int) type and alias, (const char*) name and data */ if (1 || !obj->alias) { /* Filter out signed digests (a.k.a signature algorithms) */ if (strstr(obj->name, "rsa") == NULL && strstr(obj->name, "RSA") == NULL) { Tcl_ListObjAppendElement(NULL, objPtr, Tcl_NewStringObj(obj->name,-1)); } } } |
︙ |