Index: generic/tlsDigest.c ================================================================== --- generic/tlsDigest.c +++ generic/tlsDigest.c @@ -151,11 +151,11 @@ Tcl_Obj *cipherObj, Tcl_Obj *keyObj, Tcl_Obj *macObj) { int res = 0, type = statePtr->format & 0xFF0; const EVP_MD *md = NULL; const EVP_CIPHER *cipher = NULL; const void *key = NULL, *iv = NULL, *salt = NULL; - int key_len = 0; + Tcl_Size key_len = 0; (void *) macObj; dprintf("Called"); /* Get digest */ @@ -191,29 +191,29 @@ res = (statePtr->cctx != NULL); break; } if (!res) { - Tcl_AppendResult(interp, "Create context failed", NULL); + Tcl_AppendResult(interp, "Create context failed", (char *) NULL); return TCL_ERROR; } /* Initialize cryptography function */ switch(type) { case TYPE_MD: res = EVP_DigestInit_ex(statePtr->ctx, md, NULL); break; case TYPE_HMAC: - res = HMAC_Init_ex(statePtr->hctx, key, key_len, md, NULL); + res = HMAC_Init_ex(statePtr->hctx, key, (int) key_len, md, NULL); break; case TYPE_CMAC: - res = CMAC_Init(statePtr->cctx, key, key_len, cipher, NULL); + res = CMAC_Init(statePtr->cctx, key, (int) key_len, cipher, NULL); break; } if (!res) { - Tcl_AppendResult(interp, "Initialize failed: ", REASON(), NULL); + Tcl_AppendResult(interp, "Initialize failed: ", REASON(), (char *) NULL); return TCL_ERROR; } return TCL_OK; } @@ -231,29 +231,29 @@ * Side effects: * Adds buf data to hash function or sets result to error message * *------------------------------------------------------------------- */ -int DigestUpdate(DigestState *statePtr, char *buf, size_t read, int do_result) { +int DigestUpdate(DigestState *statePtr, char *buf, Tcl_Size read, int do_result) { int res = 0; dprintf("Called"); switch(statePtr->format & 0xFF0) { case TYPE_MD: - res = EVP_DigestUpdate(statePtr->ctx, buf, read); + res = EVP_DigestUpdate(statePtr->ctx, buf, (size_t) read); break; case TYPE_HMAC: - res = HMAC_Update(statePtr->hctx, buf, read); + res = HMAC_Update(statePtr->hctx, buf, (size_t) read); break; case TYPE_CMAC: - res = CMAC_Update(statePtr->cctx, buf, read); + res = CMAC_Update(statePtr->cctx, buf, (size_t) read); break; } if (!res && do_result) { - Tcl_AppendResult(statePtr->interp, "Update failed: ", REASON(), NULL); + Tcl_AppendResult(statePtr->interp, "Update failed: ", REASON(), (char *) NULL); return TCL_ERROR; } return TCL_OK; } @@ -302,27 +302,27 @@ break; } if (!res) { if (resultObj == NULL) { - Tcl_AppendResult(interp, "Finalize failed: ", REASON(), NULL); + Tcl_AppendResult(interp, "Finalize failed: ", REASON(), (char *) NULL); } return TCL_ERROR; } /* Return message digest as either a binary or hex string */ if (statePtr->format & BIN_FORMAT) { if (resultObj == NULL) { - Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(md_buf, md_len)); + Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(md_buf, (Tcl_Size) md_len)); } else { - *resultObj = Tcl_NewByteArrayObj(md_buf, md_len); + *resultObj = Tcl_NewByteArrayObj(md_buf, (Tcl_Size) md_len); Tcl_IncrRefCount(*resultObj); } } else { Tcl_Obj *newObj = Tcl_NewObj(); - unsigned char *ptr = Tcl_SetByteArrayLength(newObj, md_len*2); + unsigned char *ptr = Tcl_SetByteArrayLength(newObj, (Tcl_Size) md_len*2); for (int i = 0; i < md_len; i++) { *ptr++ = hex[(md_buf[i] >> 4) & 0x0F]; *ptr++ = hex[md_buf[i] & 0x0F]; } @@ -395,15 +395,15 @@ /* Output message digest if not already done */ if (!(statePtr->flags & CHAN_EOF)) { Tcl_Channel parent = Tcl_GetStackedChannel(statePtr->self); Tcl_Obj *resultObj; - int written; + Tcl_Size written, toWrite; if (DigestFinalize(statePtr->interp, statePtr, &resultObj) == TCL_OK) { - unsigned char *data = Tcl_GetByteArrayFromObj(resultObj, &written); - Tcl_WriteRaw(parent, data, written); + unsigned char *data = Tcl_GetByteArrayFromObj(resultObj, &toWrite); + written = Tcl_WriteRaw(parent, data, toWrite); Tcl_DecrRefCount(resultObj); } statePtr->flags |= CHAN_EOF; } @@ -441,26 +441,26 @@ *---------------------------------------------------------------------- */ int DigestInputProc(ClientData clientData, char *buf, int toRead, int *errorCodePtr) { DigestState *statePtr = (DigestState *) clientData; Tcl_Channel parent; - int read; + Tcl_Size read; *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); + read = Tcl_ReadRaw(parent, buf, (Tcl_Size) toRead); /* Update hash function */ if (read > 0) { /* Have data */ - if (DigestUpdate(statePtr, buf, (size_t) read, 0) != TCL_OK) { + if (DigestUpdate(statePtr, buf, read, 0) != TCL_OK) { Tcl_SetChannelError(statePtr->self, Tcl_ObjPrintf("Update failed: %s", REASON())); *errorCodePtr = EINVAL; return 0; } /* This is correct */ @@ -474,21 +474,21 @@ } else if (!(statePtr->flags & CHAN_EOF)) { /* EOF */ Tcl_Obj *resultObj; if (DigestFinalize(statePtr->interp, statePtr, &resultObj) == TCL_OK) { unsigned char *data = Tcl_GetByteArrayFromObj(resultObj, &read); - memcpy(buf, data, read); + memcpy(buf, data, (int) read); Tcl_DecrRefCount(resultObj); } else { Tcl_SetChannelError(statePtr->self, Tcl_ObjPrintf("Finalize failed: %s", REASON())); *errorCodePtr = EINVAL; read = 0; } statePtr->flags |= CHAN_EOF; } - return read; + return (int) read; } /* *---------------------------------------------------------------------- * @@ -514,11 +514,11 @@ if (toWrite <= 0 || statePtr->self == (Tcl_Channel) NULL) { return 0; } /* Update hash function */ - if (DigestUpdate(statePtr, buf, (size_t) toWrite, 0) != TCL_OK) { + if (DigestUpdate(statePtr, buf, (Tcl_Size) toWrite, 0) != TCL_OK) { Tcl_SetChannelError(statePtr->self, Tcl_ObjPrintf("Update failed: %s", REASON())); *errorCodePtr = EINVAL; return 0; } return toWrite; @@ -860,11 +860,11 @@ Tcl_WrongNumArgs(interp, 1, objv, "channelId"); return TCL_ERROR; } /* Get channel */ - chan = Tcl_GetChannel(interp, Tcl_GetStringFromObj(objv[1], NULL), &mode); + chan = Tcl_GetChannel(interp, Tcl_GetStringFromObj(objv[1], (Tcl_Size *) NULL), &mode); if (chan == (Tcl_Channel) NULL) { return TCL_ERROR; } /* Make sure to operate on the topmost channel */ @@ -900,11 +900,12 @@ * *------------------------------------------------------------------- */ int DigestInstanceObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { DigestState *statePtr = (DigestState *) clientData; - int fn, data_len = 0; + int fn; + Tcl_Size data_len = 0; char *data = NULL; static const char *instance_fns [] = { "finalize", "update", NULL }; dprintf("Called"); @@ -928,11 +929,11 @@ Tcl_WrongNumArgs(interp, 1, objv, "update data"); return TCL_ERROR; } /* Update hash function */ - if (DigestUpdate(statePtr, data, (size_t) data_len, 1) != TCL_OK) { + if (DigestUpdate(statePtr, data, data_len, 1) != TCL_OK) { return TCL_ERROR; } } else { /* Finalize hash function and calculate message digest */ @@ -983,11 +984,11 @@ *------------------------------------------------------------------- */ int DigestCommandHandler(Tcl_Interp *interp, Tcl_Obj *cmdObj, Tcl_Obj *digestObj, Tcl_Obj *cipherObj, int format, Tcl_Obj *keyObj, Tcl_Obj *macObj) { DigestState *statePtr; - char *cmdName = Tcl_GetStringFromObj(cmdObj, NULL); + char *cmdName = Tcl_GetStringFromObj(cmdObj, (Tcl_Size *) NULL); dprintf("Called"); /* Create state data structure */ if ((statePtr = DigestStateNew(interp, format)) == NULL) { @@ -1032,11 +1033,11 @@ *------------------------------------------------------------------- */ int DigestDataHandler(Tcl_Interp *interp, Tcl_Obj *dataObj, Tcl_Obj *digestObj, Tcl_Obj *cipherObj, int format, Tcl_Obj *keyObj, Tcl_Obj *macObj) { char *data; - int data_len; + Tcl_Size data_len; DigestState *statePtr; dprintf("Called"); /* Get data */ @@ -1052,11 +1053,11 @@ return TCL_ERROR; } /* Calc Digest */ if (DigestInitialize(interp, statePtr, digestObj, cipherObj, keyObj, macObj) != TCL_OK || - DigestUpdate(statePtr, data, (size_t) data_len, 1) != TCL_OK || + DigestUpdate(statePtr, data, data_len, 1) != TCL_OK || DigestFinalize(interp, statePtr, NULL) != TCL_OK) { DigestStateFree(statePtr); return TCL_ERROR; } @@ -1085,11 +1086,11 @@ int DigestFileHandler(Tcl_Interp *interp, Tcl_Obj *inFileObj, Tcl_Obj *digestObj, Tcl_Obj *cipherObj, int format, Tcl_Obj *keyObj, Tcl_Obj *macObj) { DigestState *statePtr; Tcl_Channel chan = NULL; unsigned char buf[BUFFER_SIZE]; - int res = TCL_OK, len; + int res = TCL_OK; dprintf("Called"); /* Create state data structure */ if ((statePtr = DigestStateNew(interp, format)) == NULL) { @@ -1115,13 +1116,13 @@ goto done; } /* Read file data and update hash function */ while (!Tcl_Eof(chan)) { - len = Tcl_ReadRaw(chan, (char *) buf, BUFFER_SIZE); + Tcl_Size len = Tcl_ReadRaw(chan, (char *) buf, BUFFER_SIZE); if (len > 0) { - if ((res = DigestUpdate(statePtr, &buf[0], (size_t) len, 1)) != TCL_OK) { + if ((res = DigestUpdate(statePtr, &buf[0], len, 1)) != TCL_OK) { goto done; } } } @@ -1165,11 +1166,12 @@ * Sets result to message digest or error message * *------------------------------------------------------------------- */ static int DigestMain(int type, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - int start = 1, format = HEX_FORMAT, res = TCL_OK, fn; + int start = 1, format = HEX_FORMAT, res = TCL_OK; + Tcl_Size fn; Tcl_Obj *cipherObj = NULL, *cmdObj = NULL, *dataObj = NULL, *digestObj = NULL; Tcl_Obj *fileObj = NULL, *keyObj = NULL, *macObj = NULL; const char *channel = NULL, *opt; dprintf("Called"); @@ -1182,11 +1184,11 @@ Tcl_WrongNumArgs(interp, 1, objv, "?-bin|-hex? ?-cipher name? ?-digest name? ?-key key? ?-mac name? [-channel chan | -command cmdName | -file filename | ?-data? data]"); return TCL_ERROR; } /* Special case of first arg is digest, cipher, or mac */ - opt = Tcl_GetStringFromObj(objv[start], NULL); + opt = Tcl_GetStringFromObj(objv[start], (Tcl_Size *) NULL); if (opt[0] != '-') { switch(type) { case TYPE_MD: case TYPE_HMAC: digestObj = objv[start++]; @@ -1202,11 +1204,11 @@ /* Get options */ for (int idx = start; idx < objc; idx++) { /* Special case for when last arg is data */ if (idx == objc - 1) { - opt = Tcl_GetStringFromObj(objv[idx], NULL); + opt = Tcl_GetStringFromObj(objv[idx], (Tcl_Size *) NULL); if (opt[0] != '-' && dataObj == NULL) { dataObj = objv[idx]; break; } } @@ -1274,21 +1276,21 @@ } } if (type == TYPE_MAC) { if (macObj != NULL) { - char *macName = Tcl_GetStringFromObj(macObj, NULL); + char *macName = Tcl_GetStringFromObj(macObj, (Tcl_Size *) 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); + Tcl_AppendResult(interp, "invalid MAC \"", macName, "\"", (char *) NULL); return TCL_ERROR; } } else { - Tcl_AppendResult(interp, "no MAC", NULL); + Tcl_AppendResult(interp, "no MAC", (char *) NULL); return TCL_ERROR; } } /* Calc digest on file, stacked channel, using instance command, or data blob */ @@ -1299,11 +1301,11 @@ } else if (cmdObj != NULL) { res = DigestCommandHandler(interp, cmdObj, digestObj, cipherObj, format | type, keyObj, macObj); } else if (dataObj != NULL) { res = DigestDataHandler(interp, dataObj, digestObj, cipherObj, format | type, keyObj, macObj); } else { - Tcl_AppendResult(interp, "No operation: Use -channel, -command, -data, or -file option", NULL); + Tcl_AppendResult(interp, "No operation: Use -channel, -command, -data, or -file option", (char *) NULL); res = TCL_ERROR; } return res; } Index: generic/tlsEncrypt.c ================================================================== --- generic/tlsEncrypt.c +++ generic/tlsEncrypt.c @@ -137,11 +137,12 @@ */ int EncryptInitialize(Tcl_Interp *interp, int type, EVP_CIPHER_CTX **ctx, Tcl_Obj *cipherObj, Tcl_Obj *keyObj, Tcl_Obj *ivObj) { const EVP_CIPHER *cipher; char *keyString = NULL, *ivString = NULL; - int cipher_len = 0, key_len = 0, iv_len = 0, res, max; + Tcl_Size key_len = 0, iv_len = 0; + int res, max; unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH]; dprintf("Called"); /* Init buffers */ @@ -185,11 +186,11 @@ } else { res = EVP_DecryptInit_ex(*ctx, cipher, NULL, key, iv); } if(!res) { - Tcl_AppendResult(interp, "Initialize failed: ", REASON(), NULL); + Tcl_AppendResult(interp, "Initialize failed: ", REASON(), (char *) NULL); return TCL_ERROR; } /* Erase buffers */ memset(key, 0, EVP_MAX_KEY_LENGTH); @@ -211,26 +212,26 @@ * Adds encrypted data to buffer or sets result to error message * *------------------------------------------------------------------- */ int EncryptUpdate(Tcl_Interp *interp, int type, EVP_CIPHER_CTX *ctx, unsigned char *out_buf, - int *out_len, unsigned char *data, int data_len) { + int *out_len, unsigned char *data, Tcl_Size data_len) { int res; dprintf("Called"); /* Encrypt/decrypt data */ if (type == TYPE_ENCRYPT) { - res = EVP_EncryptUpdate(ctx, out_buf, out_len, data, data_len); + res = EVP_EncryptUpdate(ctx, out_buf, out_len, data, (int) data_len); } else { - res = EVP_DecryptUpdate(ctx, out_buf, out_len, data, data_len); + res = EVP_DecryptUpdate(ctx, out_buf, out_len, data, (int) data_len); } if (res) { return TCL_OK; } else { - Tcl_AppendResult(interp, "Update failed: ", REASON(), NULL); + Tcl_AppendResult(interp, "Update failed: ", REASON(), (char *) NULL); return TCL_ERROR; } } /* @@ -263,11 +264,11 @@ } if (res) { return TCL_OK; } else { - Tcl_AppendResult(interp, "Finalize failed: ", REASON(), NULL); + Tcl_AppendResult(interp, "Finalize failed: ", REASON(), (char *) NULL); return TCL_ERROR; } } /*******************************************************************/ @@ -333,11 +334,11 @@ unsigned char out_buf[EVP_MAX_BLOCK_LENGTH]; /* Finalize function */ if (EncryptFinalize(interp, statePtr->type, statePtr->ctx, out_buf, &out_len) == TCL_OK) { if (out_len > 0) { - int len = Tcl_WriteRaw(parent, (const char *) out_buf, out_len); + Tcl_Size len = Tcl_WriteRaw(parent, (const char *) out_buf, (Tcl_Size) out_len); if (len < 0) { return Tcl_GetErrno(); } } } else { @@ -380,31 +381,32 @@ *---------------------------------------------------------------------- */ int EncryptInputProc(ClientData clientData, char *buf, int toRead, int *errorCodePtr) { EncryptState *statePtr = (EncryptState *) clientData; Tcl_Channel parent; - int read, out_len; + int out_len; + Tcl_Size read; *errorCodePtr = 0; char *in_buf; /* Abort if nothing to process */ if (toRead <= 0 || statePtr->self == (Tcl_Channel) NULL) { return 0; } /* Get bytes from underlying channel */ - in_buf = Tcl_Alloc(toRead); + in_buf = Tcl_Alloc((Tcl_Size) toRead); parent = Tcl_GetStackedChannel(statePtr->self); - read = Tcl_ReadRaw(parent, in_buf, toRead); + read = Tcl_ReadRaw(parent, in_buf, (Tcl_Size) toRead); /* Update function */ if (read > 0) { /* Have data - Update function */ if (EncryptUpdate(statePtr->interp, statePtr->type, statePtr->ctx, buf, &out_len, in_buf, read) == TCL_OK) { /* If have data, put in buf, otherwise tell TCL to try again */ if (out_len > 0) { - read = out_len; + read = (Tcl_Size) out_len; } else { *errorCodePtr = EAGAIN; read = -1; } } else { @@ -418,21 +420,21 @@ *errorCodePtr = Tcl_GetErrno(); } else if (!(statePtr->flags & CHAN_EOF)) { /* EOF - Finalize function and put any remaining data in buf */ if (EncryptFinalize(statePtr->interp, statePtr->type, statePtr->ctx, buf, &out_len) == TCL_OK) { - read = out_len; + read = (Tcl_Size) out_len; } else { Tcl_SetChannelError(statePtr->self, Tcl_ObjPrintf("Finalize failed: %s", REASON())); *errorCodePtr = EINVAL; read = 0; } statePtr->flags |= CHAN_EOF; } Tcl_Free(in_buf); - return read; + return (int) read; } /* *---------------------------------------------------------------------- * @@ -459,18 +461,18 @@ /* Abort if nothing to process */ if (toWrite <= 0 || statePtr->self == (Tcl_Channel) NULL) { return 0; } - out_buf = Tcl_Alloc(toWrite+EVP_MAX_BLOCK_LENGTH); + out_buf = Tcl_Alloc((Tcl_Size) toWrite+EVP_MAX_BLOCK_LENGTH); /* Update function */ - if (EncryptUpdate(statePtr->interp, statePtr->type, statePtr->ctx, out_buf, &out_len, buf, toWrite) == TCL_OK) { + if (EncryptUpdate(statePtr->interp, statePtr->type, statePtr->ctx, out_buf, &out_len, buf, (Tcl_Size) toWrite) == TCL_OK) { /* If have data, output it, otherwise tell TCL to try again */ if (out_len > 0) { Tcl_Channel parent = Tcl_GetStackedChannel(statePtr->self); - write = Tcl_WriteRaw(parent, (const char *) out_buf, out_len); + write = (int) Tcl_WriteRaw(parent, (const char *) out_buf, (Tcl_Size) out_len); write = toWrite; } else { *errorCodePtr = EAGAIN; write = -1; } @@ -818,11 +820,11 @@ Tcl_WrongNumArgs(interp, 1, objv, "channelId"); return TCL_ERROR; } /* Get channel */ - chan = Tcl_GetChannel(interp, Tcl_GetStringFromObj(objv[1], NULL), &mode); + chan = Tcl_GetChannel(interp, Tcl_GetStringFromObj(objv[1], (Tcl_Size *) NULL), &mode); if (chan == (Tcl_Channel) NULL) { return TCL_ERROR; } /* Make sure to operate on the topmost channel */ @@ -858,11 +860,12 @@ * *------------------------------------------------------------------- */ int EncryptInstanceObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { EncryptState *statePtr = (EncryptState *) clientData; - int fn, data_len = 0, out_len; + int fn, out_len; + Tcl_Size data_len = 0; char *data = NULL; Tcl_Obj *resultObj; unsigned char *out_buf; static const char *instance_fns [] = { "finalize", "update", NULL }; @@ -899,21 +902,21 @@ return TCL_ERROR; } /* Update function */ if (EncryptUpdate(interp, statePtr->type, statePtr->ctx, out_buf, &out_len, data, data_len) == TCL_OK) { - out_buf = Tcl_SetByteArrayLength(resultObj, out_len); + out_buf = Tcl_SetByteArrayLength(resultObj, (Tcl_Size) out_len); Tcl_SetObjResult(interp, resultObj); } else { Tcl_DecrRefCount(resultObj); return TCL_ERROR; } } else { /* Finalize function */ if (EncryptFinalize(interp, statePtr->type, statePtr->ctx, out_buf, &out_len) == TCL_OK) { - out_buf = Tcl_SetByteArrayLength(resultObj, out_len); + out_buf = Tcl_SetByteArrayLength(resultObj, (Tcl_Size) out_len); Tcl_SetObjResult(interp, resultObj); } else { Tcl_DecrRefCount(resultObj); return TCL_ERROR; } @@ -962,11 +965,11 @@ *------------------------------------------------------------------- */ int EncryptCommandHandler(Tcl_Interp *interp, int type, Tcl_Obj *cmdObj, Tcl_Obj *cipherObj, Tcl_Obj *digestObj, Tcl_Obj *keyObj, Tcl_Obj *ivObj) { EncryptState *statePtr; - char *cmdName = Tcl_GetStringFromObj(cmdObj, NULL); + char *cmdName = Tcl_GetStringFromObj(cmdObj, (Tcl_Size *) NULL); (void *) digestObj; dprintf("Called"); if ((statePtr = EncryptStateNew(interp, type)) == NULL) { @@ -1007,11 +1010,12 @@ *------------------------------------------------------------------- */ int EncryptDataHandler(Tcl_Interp *interp, int type, Tcl_Obj *dataObj, Tcl_Obj *cipherObj, Tcl_Obj *digestObj, Tcl_Obj *keyObj, Tcl_Obj *ivObj) { EVP_CIPHER_CTX *ctx = NULL; - int data_len = 0, out_len = 0, len = 0, res = TCL_OK; + int out_len = 0, len = 0, res = TCL_OK; + Tcl_Size data_len = 0; unsigned char *data, *out_buf; Tcl_Obj *resultObj; (void *) digestObj; dprintf("Called"); @@ -1018,11 +1022,11 @@ /* Get data */ if (dataObj != NULL) { data = Tcl_GetByteArrayFromObj(dataObj, &data_len); } else { - Tcl_AppendResult(interp, "No data", NULL); + Tcl_AppendResult(interp, "No data", (char *) NULL); return TCL_ERROR; } /* Allocate storage for result. Size should be data size + block size. */ resultObj = Tcl_NewObj(); @@ -1042,11 +1046,11 @@ out_len += len; done: /* Set output result */ if (res == TCL_OK) { - out_buf = Tcl_SetByteArrayLength(resultObj, out_len); + out_buf = Tcl_SetByteArrayLength(resultObj, (Tcl_Size) out_len); Tcl_SetObjResult(interp, resultObj); } else { Tcl_DecrRefCount(resultObj); /* Result is error message */ } @@ -1103,15 +1107,15 @@ goto done; } /* Read file data from inFile, encrypt/decrypt it, then output to outFile */ while (!Tcl_Eof(in)) { - int read = Tcl_ReadRaw(in, (char *) in_buf, BUFFER_SIZE); + Tcl_Size read = Tcl_ReadRaw(in, (char *) in_buf, BUFFER_SIZE); if (read > 0) { if ((res = EncryptUpdate(interp, type, ctx, out_buf, &out_len, in_buf, read)) == TCL_OK) { if (out_len > 0) { - len = Tcl_WriteRaw(out, (const char *) out_buf, out_len); + len = (int) Tcl_WriteRaw(out, (const char *) out_buf, (Tcl_Size) out_len); if (len >= 0) { total += len; } else { Tcl_AppendResult(interp, "Write error: ", Tcl_ErrnoMsg(Tcl_GetErrno()), (char *) NULL); res = TCL_ERROR; @@ -1129,11 +1133,11 @@ } /* Finalize data and write any remaining data in block */ if ((res = EncryptFinalize(interp, type, ctx, out_buf, &out_len)) == TCL_OK) { if (out_len > 0) { - len = Tcl_WriteRaw(out, (const char *) out_buf, out_len); + len = (int) Tcl_WriteRaw(out, (const char *) out_buf, (Tcl_Size) out_len); if (len >= 0) { total += len; } else { Tcl_AppendResult(interp, "Write error: ", Tcl_ErrnoMsg(Tcl_GetErrno()), (char *) NULL); res = TCL_ERROR; @@ -1187,11 +1191,12 @@ */ static int EncryptMain(int type, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { Tcl_Obj *cipherObj = NULL, *cmdObj = NULL, *dataObj = NULL, *digestObj = NULL; Tcl_Obj *inFileObj = NULL, *outFileObj = NULL, *keyObj = NULL, *ivObj = NULL, *macObj = NULL; const char *channel = NULL, *opt; - int res, start = 1, fn; + int res, start = 1; + Tcl_Size fn; dprintf("Called"); /* Clear interp result */ Tcl_ResetResult(interp); @@ -1201,11 +1206,11 @@ Tcl_WrongNumArgs(interp, 1, objv, "?-cipher? name ?-digest name? -key key ?-iv string? ?-mac name? [-channel chan | -command cmdName | -infile filename -outfile filename | ?-data? data]"); return TCL_ERROR; } /* Special case of first arg is cipher */ - opt = Tcl_GetStringFromObj(objv[start], NULL); + opt = Tcl_GetStringFromObj(objv[start], (Tcl_Size *) NULL); if (opt[0] != '-') { switch(type) { case TYPE_ENCRYPT: case TYPE_DECRYPT: cipherObj = objv[start++]; @@ -1215,11 +1220,11 @@ /* Get options */ for (int idx = start; idx < objc; idx++) { /* Special case for when last arg is data */ if (idx == objc - 1) { - opt = Tcl_GetStringFromObj(objv[idx], NULL); + opt = Tcl_GetStringFromObj(objv[idx], (Tcl_Size *) NULL); if (opt[0] != '-' && dataObj == NULL) { dataObj = objv[idx]; break; } } @@ -1272,13 +1277,13 @@ } } /* Check for required options */ if (cipherObj == NULL) { - Tcl_AppendResult(interp, "No cipher", NULL); + Tcl_AppendResult(interp, "No cipher", (char *) NULL); } else if (keyObj == NULL) { - Tcl_AppendResult(interp, "No key", NULL); + Tcl_AppendResult(interp, "No key", (char *) NULL); return TCL_ERROR; } /* Perform encryption function on file, stacked channel, using instance command, or data blob */ if (inFileObj != NULL && outFileObj != NULL) { @@ -1288,11 +1293,11 @@ } else if (cmdObj != NULL) { res = EncryptCommandHandler(interp, type, cmdObj, cipherObj, digestObj, keyObj, ivObj); } else if (dataObj != NULL) { res = EncryptDataHandler(interp, type, dataObj, cipherObj, digestObj, keyObj, ivObj); } else { - Tcl_AppendResult(interp, "No operation specified: Use -channel, -command, -data, or -infile option", NULL); + Tcl_AppendResult(interp, "No operation specified: Use -channel, -command, -data, or -infile option", (char *) NULL); res = TCL_ERROR; } return res; } Index: generic/tlsInfo.c ================================================================== --- generic/tlsInfo.c +++ generic/tlsInfo.c @@ -42,11 +42,11 @@ void NamesCallback(const OBJ_NAME *obj, void *arg) { Tcl_Obj *listObj = (Tcl_Obj *) arg; /* Fields: (int) type and alias, (const char*) name (alias from) and data (alias to) */ if (strstr(obj->name, "rsa") == NULL && strstr(obj->name, "RSA") == NULL) { - Tcl_ListObjAppendElement(NULL, listObj, Tcl_NewStringObj(obj->name,-1)); + Tcl_ListObjAppendElement(NULL, listObj, Tcl_NewStringObj(obj->name, -1)); } } /*******************************************************************/ @@ -68,17 +68,17 @@ int CipherInfo(Tcl_Interp *interp, Tcl_Obj *nameObj) { const EVP_CIPHER *cipher; Tcl_Obj *resultObj, *listObj; unsigned long flags, mode; unsigned char *modeName = NULL; - char *name = Tcl_GetStringFromObj(nameObj,NULL); + char *name = Tcl_GetStringFromObj(nameObj, (Tcl_Size *) NULL); /* Get cipher */ cipher = EVP_get_cipherbyname(name); if (cipher == NULL) { - Tcl_AppendResult(interp, "Invalid cipher \"", name, "\"", NULL); + Tcl_AppendResult(interp, "Invalid cipher \"", name, "\"", (char *) NULL); return TCL_ERROR; } /* Get properties */ resultObj = Tcl_NewListObj(0, NULL); @@ -262,11 +262,12 @@ */ 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, res = TCL_OK; + Tcl_Size index; + int verbose = 0, use_supported = 0, res = TCL_OK; int min_version, max_version; (void) clientData; dprintf("Called"); @@ -292,51 +293,51 @@ return TCL_ERROR; } switch ((enum protocol)index) { case TLS_SSL2: - Tcl_AppendResult(interp, protocols[index], ": protocol not supported", NULL); + Tcl_AppendResult(interp, protocols[index], ": protocol not supported", (char *) NULL); return TCL_ERROR; case TLS_SSL3: #if defined(NO_SSL3) || defined(OPENSSL_NO_SSL3) || defined(OPENSSL_NO_SSL3_METHOD) - Tcl_AppendResult(interp, protocols[index], ": protocol not supported", NULL); + Tcl_AppendResult(interp, protocols[index], ": protocol not supported", (char *) NULL); return TCL_ERROR; #else min_version = SSL3_VERSION; max_version = SSL3_VERSION; break; #endif case TLS_TLS1: #if defined(NO_TLS1) || defined(OPENSSL_NO_TLS1) || defined(OPENSSL_NO_TLS1_METHOD) - Tcl_AppendResult(interp, protocols[index], ": protocol not supported", NULL); + Tcl_AppendResult(interp, protocols[index], ": protocol not supported", (char *) NULL); return TCL_ERROR; #else min_version = TLS1_VERSION; max_version = TLS1_VERSION; break; #endif case TLS_TLS1_1: #if defined(NO_TLS1_1) || defined(OPENSSL_NO_TLS1_1) || defined(OPENSSL_NO_TLS1_1_METHOD) - Tcl_AppendResult(interp, protocols[index], ": protocol not supported", NULL); + Tcl_AppendResult(interp, protocols[index], ": protocol not supported", (char *) NULL); return TCL_ERROR; #else min_version = TLS1_1_VERSION; max_version = TLS1_1_VERSION; break; #endif case TLS_TLS1_2: #if defined(NO_TLS1_2) || defined(OPENSSL_NO_TLS1_2) || defined(OPENSSL_NO_TLS1_2_METHOD) - Tcl_AppendResult(interp, protocols[index], ": protocol not supported", NULL); + Tcl_AppendResult(interp, protocols[index], ": protocol not supported", (char *) NULL); return TCL_ERROR; #else min_version = TLS1_2_VERSION; max_version = TLS1_2_VERSION; break; #endif case TLS_TLS1_3: #if defined(NO_TLS1_3) || defined(OPENSSL_NO_TLS1_3) - Tcl_AppendResult(interp, protocols[index], ": protocol not supported", NULL); + Tcl_AppendResult(interp, protocols[index], ": protocol not supported", (char *) NULL); return TCL_ERROR; #else min_version = TLS1_3_VERSION; max_version = TLS1_3_VERSION; break; @@ -347,11 +348,11 @@ break; } /* Create context */ if ((ctx = SSL_CTX_new(TLS_server_method())) == NULL) { - Tcl_AppendResult(interp, REASON(), NULL); + Tcl_AppendResult(interp, REASON(), (char *) NULL); return TCL_ERROR; } /* Set protocol versions */ if (SSL_CTX_set_min_proto_version(ctx, min_version) == 0 || @@ -360,11 +361,11 @@ return TCL_ERROR; } /* Create SSL context */ if ((ssl = SSL_new(ctx)) == NULL) { - Tcl_AppendResult(interp, REASON(), NULL); + Tcl_AppendResult(interp, REASON(), (char *) NULL); SSL_CTX_free(ctx); return TCL_ERROR; } /* Use list and order as would be sent in a ClientHello or all available ciphers */ @@ -396,11 +397,11 @@ Tcl_ListObjAppendElement(interp, resultObj, Tcl_NewStringObj(cp, -1)); } } else { char buf[BUFSIZ]; - resultObj = Tcl_NewStringObj("",0); + resultObj = Tcl_NewStringObj("", 0); if (resultObj == NULL) { res = TCL_ERROR; goto done; } @@ -450,17 +451,17 @@ int DigestInfo(Tcl_Interp *interp, Tcl_Obj *nameObj) { EVP_MD *md; Tcl_Obj *resultObj, *listObj; unsigned long flags; int res = TCL_OK; - char *name = Tcl_GetStringFromObj(nameObj,NULL); + char *name = Tcl_GetStringFromObj(nameObj, (Tcl_Size *) NULL); /* Get message digest */ md = EVP_get_digestbyname(name); if (md == NULL) { - Tcl_AppendResult(interp, "Invalid digest \"", name, "\"", NULL); + Tcl_AppendResult(interp, "Invalid digest \"", name, "\"", (char *) NULL); return TCL_ERROR; } /* Get properties */ resultObj = Tcl_NewListObj(0, NULL); @@ -643,14 +644,14 @@ *------------------------------------------------------------------- */ int MacInfo(Tcl_Interp *interp, Tcl_Obj *nameObj) { Tcl_Obj *resultObj; int res = TCL_OK; - char *name = Tcl_GetStringFromObj(nameObj,NULL); + char *name = Tcl_GetStringFromObj(nameObj, (Tcl_Size *) NULL); if (strcmp(name, "cmac") != 0 && strcmp(name, "hmac") != 0) { - Tcl_AppendResult(interp, "Invalid MAC \"", name, "\"", NULL); + Tcl_AppendResult(interp, "Invalid MAC \"", name, "\"", (char *) NULL); return TCL_ERROR; } /* Get properties */ resultObj = Tcl_NewListObj(0, NULL); @@ -748,15 +749,15 @@ *------------------------------------------------------------------- */ int PkeyInfo(Tcl_Interp *interp, Tcl_Obj *nameObj) { Tcl_Obj *resultObj; int res = TCL_OK; - char *name = Tcl_GetStringFromObj(nameObj,NULL); + char *name = Tcl_GetStringFromObj(nameObj, (Tcl_Size *) NULL); EVP_PKEY *pkey = NULL; if (pkey == NULL) { - Tcl_AppendResult(interp, "Invalid public key method \"", name, "\"", NULL); + Tcl_AppendResult(interp, "Invalid public key method \"", name, "\"", (char *) NULL); return TCL_ERROR; } /* Get properties */ resultObj = Tcl_NewListObj(0, NULL); Index: generic/tlsInt.h ================================================================== --- generic/tlsInt.h +++ generic/tlsInt.h @@ -39,15 +39,21 @@ #endif /* * Backwards compatibility for size type change */ #if TCL_MAJOR_VERSION < 9 && TCL_MINOR_VERSION < 7 + #include + #define TCL_SIZE_MAX INT_MAX + #ifndef Tcl_Size typedef int Tcl_Size; #endif #define TCL_SIZE_MODIFIER "" + #define Tcl_GetSizeIntFromObj Tcl_GetIntFromObj + #define Tcl_NewSizeIntObj Tcl_NewIntObj + #define Tcl_NewSizeIntFromObj Tcl_NewWideIntObj #endif #include #include #include @@ -206,16 +212,16 @@ BIO *BIO_new_tcl(State* statePtr, int flags); EVP_CIPHER *Util_GetCipher(Tcl_Interp *interp, Tcl_Obj *cipherObj, int no_null); EVP_MD *Util_GetDigest(Tcl_Interp *interp, Tcl_Obj *digestObj, int no_null); -unsigned char *Util_GetIV(Tcl_Interp *interp, Tcl_Obj *ivObj, int *len, int max, int no_null); -unsigned char *Util_GetKey(Tcl_Interp *interp, Tcl_Obj *keyObj, int *len, char *name, int max, int no_null); -unsigned char *Util_GetSalt(Tcl_Interp *interp, Tcl_Obj *saltObj, int *len, int max, int no_null); +unsigned char *Util_GetIV(Tcl_Interp *interp, Tcl_Obj *ivObj, Tcl_Size *len, int max, int no_null); +unsigned char *Util_GetKey(Tcl_Interp *interp, Tcl_Obj *keyObj, Tcl_Size *len, char *name, int max, int no_null); +unsigned char *Util_GetSalt(Tcl_Interp *interp, Tcl_Obj *saltObj, Tcl_Size *len, int max, int no_null); int Util_GetInt(Tcl_Interp *interp, Tcl_Obj *dataObj, int *value, char *name, int min, int max); #if OPENSSL_VERSION_NUMBER >= 0x30000000L EVP_MAC *Util_GetMAC(Tcl_Interp *interp, Tcl_Obj *MacObj, int no_null); #endif #define PTR2INT(x) ((int) ((intptr_t) (x))) #endif /* _TLSINT_H */ Index: generic/tlsKDF.c ================================================================== --- generic/tlsKDF.c +++ generic/tlsKDF.c @@ -40,11 +40,11 @@ * Sets result to a list of key and iv values, or an error message * *------------------------------------------------------------------- */ static int KDF_PBKDF2(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - int pass_len = 0, salt_len = 0, fn; + Tcl_Size fn, salt_len = 0, pass_len = 0; int iklen, ivlen, iter = 1; unsigned char *pass = NULL, *salt = NULL; const EVP_MD *md = NULL; const EVP_CIPHER *cipher = NULL; int buf_len = (EVP_MAX_KEY_LENGTH + EVP_MAX_IV_LENGTH)*4, dk_len = buf_len; @@ -73,11 +73,11 @@ return TCL_ERROR; } /* Validate arg has a value */ if (++idx >= objc) { - Tcl_AppendResult(interp, "No value for option \"", command_opts[fn], "\"", NULL); + Tcl_AppendResult(interp, "No value for option \"", command_opts[fn], "\"", (char *) NULL); return TCL_ERROR; } switch(fn) { case _opt_cipher: @@ -112,11 +112,11 @@ } } /* Validate options */ if (md == NULL) { - Tcl_AppendResult(interp, "no digest", NULL); + Tcl_AppendResult(interp, "no digest", (char *) NULL); return TCL_ERROR; } /* Set output type sizes */ if (cipher == NULL) { @@ -128,22 +128,22 @@ ivlen = EVP_CIPHER_iv_length(cipher); dk_len = iklen+ivlen; } /* Derive key */ - if (!PKCS5_PBKDF2_HMAC(pass, pass_len, salt, salt_len, iter, md, dk_len, tmpkeyiv)) { - Tcl_AppendResult(interp, "Key derivation failed: ", REASON(), NULL); + if (!PKCS5_PBKDF2_HMAC(pass, (int) pass_len, salt, (int) salt_len, iter, md, dk_len, tmpkeyiv)) { + Tcl_AppendResult(interp, "Key derivation failed: ", REASON(), (char *) NULL); return TCL_ERROR; } /* Set result to key and iv */ if (cipher == NULL) { - Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(tmpkeyiv, dk_len)); + Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(tmpkeyiv, (Tcl_Size) dk_len)); } else { Tcl_Obj *resultObj = Tcl_NewListObj(0, NULL); - LAPPEND_BARRAY(interp, resultObj, "key", tmpkeyiv, iklen); - LAPPEND_BARRAY(interp, resultObj, "iv", tmpkeyiv+iklen, ivlen); + LAPPEND_BARRAY(interp, resultObj, "key", tmpkeyiv, (Tcl_Size) iklen); + LAPPEND_BARRAY(interp, resultObj, "iv", tmpkeyiv+iklen, (Tcl_Size) ivlen); Tcl_SetObjResult(interp, resultObj); } /* Clear data */ memset(tmpkeyiv, 0, buf_len); @@ -168,11 +168,13 @@ */ static int KDF_HKDF(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { EVP_PKEY_CTX *pctx = NULL; const EVP_MD *md = NULL; unsigned char *salt = NULL, *key = NULL, *info = NULL, *out = NULL; - int salt_len = 0, key_len = 0, info_len = 0, res = TCL_OK, fn; + Tcl_Size salt_len = 0, key_len = 0, info_len = 0; + int res = TCL_OK; + Tcl_Size fn; int dk_len = EVP_MAX_KEY_LENGTH + EVP_MAX_IV_LENGTH; size_t out_len; Tcl_Obj *resultObj; (void) clientData; @@ -195,11 +197,11 @@ return TCL_ERROR; } /* Validate arg has a value */ if (++idx >= objc) { - Tcl_AppendResult(interp, "No value for option \"", command_opts[fn], "\"", NULL); + Tcl_AppendResult(interp, "No value for option \"", command_opts[fn], "\"", (char *) NULL); return TCL_ERROR; } switch(fn) { case _opt_digest: @@ -229,66 +231,66 @@ break; } } if (md == NULL) { - Tcl_AppendResult(interp, "no digest", NULL); + Tcl_AppendResult(interp, "no digest", (char *) NULL); goto error; } if (key == NULL) { - Tcl_AppendResult(interp, "no key", NULL); + Tcl_AppendResult(interp, "no key", (char *) NULL); goto error; } /* Create context */ pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL); if (pctx == NULL) { - Tcl_AppendResult(interp, "Memory allocation error", NULL); + Tcl_AppendResult(interp, "Memory allocation error", (char *) NULL); goto error; } if (EVP_PKEY_derive_init(pctx) < 1) { - Tcl_AppendResult(interp, "Initialize failed: ", REASON(), NULL); + Tcl_AppendResult(interp, "Initialize failed: ", REASON(), (char *) NULL); goto error; } /* Set config parameters */ if (EVP_PKEY_CTX_set_hkdf_md(pctx, md) < 1) { - Tcl_AppendResult(interp, "Set digest failed: ", REASON(), NULL); + Tcl_AppendResult(interp, "Set digest failed: ", REASON(), (char *) NULL); + goto error; + } + if (EVP_PKEY_CTX_set1_hkdf_key(pctx, key, (int) key_len) < 1) { + Tcl_AppendResult(interp, "Set key failed: ", REASON(), (char *) NULL); goto error; } - if (EVP_PKEY_CTX_set1_hkdf_key(pctx, key, key_len) < 1) { - Tcl_AppendResult(interp, "Set key failed: ", REASON(), NULL); + if (salt != NULL && EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, (int) salt_len) < 1) { + Tcl_AppendResult(interp, "Set salt failed: ", REASON(), (char *) NULL); goto error; } - if (salt != NULL && EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, salt_len) < 1) { - Tcl_AppendResult(interp, "Set salt failed: ", REASON(), NULL); - goto error; - } - if (info != NULL && EVP_PKEY_CTX_add1_hkdf_info(pctx, info, info_len) < 1) { - Tcl_AppendResult(interp, "Set info failed: ", REASON(), NULL); + if (info != NULL && EVP_PKEY_CTX_add1_hkdf_info(pctx, info, (int) info_len) < 1) { + Tcl_AppendResult(interp, "Set info failed: ", REASON(), (char *) NULL); goto error; } /* Get buffer */ resultObj = Tcl_NewObj(); - if ((out = Tcl_SetByteArrayLength(resultObj, dk_len)) == NULL) { + if ((out = Tcl_SetByteArrayLength(resultObj, (Tcl_Size) dk_len)) == NULL) { Tcl_AppendResult(interp, "Memory allocation error", (char *) NULL); goto error; } out_len = (size_t) dk_len; /* Derive key */ if (EVP_PKEY_derive(pctx, out, &out_len) > 0) { /* Shrink buffer to actual size */ - Tcl_SetByteArrayLength(resultObj, (int) out_len); + Tcl_SetByteArrayLength(resultObj, (Tcl_Size) out_len); Tcl_SetObjResult(interp, resultObj); res = TCL_OK; goto done; } else { - Tcl_AppendResult(interp, "Key derivation failed: ", REASON(), NULL); + Tcl_AppendResult(interp, "Key derivation failed: ", REASON(), (char *) NULL); Tcl_DecrRefCount(resultObj); } error: res = TCL_ERROR; @@ -316,11 +318,13 @@ *------------------------------------------------------------------- */ static int KDF_Scrypt(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { EVP_PKEY_CTX *pctx = NULL; unsigned char *salt = NULL, *pass = NULL, *out = NULL; - int salt_len = 0, pass_len = 0, dk_len = 64, res = TCL_OK, fn; + Tcl_Size salt_len = 0, pass_len = 0; + int dk_len = 64, res = TCL_OK; + Tcl_Size fn; uint64_t N = 0, p = 0, r = 0, maxmem = 0; size_t out_len; Tcl_Obj *resultObj; (void) clientData; @@ -392,57 +396,57 @@ Tcl_AppendResult(interp, "Memory allocation error", (char *) NULL); goto error; } if (EVP_PKEY_derive_init(pctx) < 1) { - Tcl_AppendResult(interp, "Initialize failed: ", REASON(), NULL); + Tcl_AppendResult(interp, "Initialize failed: ", REASON(), (char *) NULL); goto error; } /* Set config parameters */ - if (EVP_PKEY_CTX_set1_pbe_pass(pctx, pass, pass_len) < 1) { - Tcl_AppendResult(interp, "Set key failed: ", REASON(), NULL); + if (EVP_PKEY_CTX_set1_pbe_pass(pctx, pass, (int) pass_len) < 1) { + Tcl_AppendResult(interp, "Set key failed: ", REASON(), (char *) NULL); goto error; } - if (EVP_PKEY_CTX_set1_scrypt_salt(pctx, salt, salt_len) < 1) { - Tcl_AppendResult(interp, "Set salt failed: ", REASON(), NULL); + if (EVP_PKEY_CTX_set1_scrypt_salt(pctx, salt, (int) salt_len) < 1) { + Tcl_AppendResult(interp, "Set salt failed: ", REASON(), (char *) NULL); goto error; } if (N != 0 && EVP_PKEY_CTX_set_scrypt_N(pctx, N) < 1) { - Tcl_AppendResult(interp, "Set cost parameter (N) failed: ", REASON(), NULL); + Tcl_AppendResult(interp, "Set cost parameter (N) failed: ", REASON(), (char *) NULL); goto error; } if (r != 0 && EVP_PKEY_CTX_set_scrypt_r(pctx, r) < 1) { - Tcl_AppendResult(interp, "Set lock size parameter (r) failed: ", REASON(), NULL); + Tcl_AppendResult(interp, "Set lock size parameter (r) failed: ", REASON(), (char *) NULL); goto error; } if (p != 0 && EVP_PKEY_CTX_set_scrypt_p(pctx, p) < 1) { - Tcl_AppendResult(interp, "Set Parallelization parameter (p) failed: ", REASON(), NULL); + Tcl_AppendResult(interp, "Set Parallelization parameter (p) failed: ", REASON(), (char *) NULL); goto error; } if (maxmem != 0 && EVP_PKEY_CTX_set_scrypt_maxmem_bytes(pctx, maxmem) < 1) { - Tcl_AppendResult(interp, "Set max memory failed: ", REASON(), NULL); + Tcl_AppendResult(interp, "Set max memory failed: ", REASON(), (char *) NULL); goto error; } /* Get buffer */ resultObj = Tcl_NewObj(); - if ((out = Tcl_SetByteArrayLength(resultObj, dk_len)) == NULL) { + if ((out = Tcl_SetByteArrayLength(resultObj, (Tcl_Size) dk_len)) == NULL) { Tcl_AppendResult(interp, "Memory allocation error", (char *) NULL); goto error; } out_len = (size_t) dk_len; /* Derive key */ if (EVP_PKEY_derive(pctx, out, &out_len) > 0) { /* Shrink buffer to actual size */ - Tcl_SetByteArrayLength(resultObj, (int) out_len); + Tcl_SetByteArrayLength(resultObj, (Tcl_Size) out_len); Tcl_SetObjResult(interp, resultObj); goto done; } else { - Tcl_AppendResult(interp, "Key derivation failed: ", REASON(), NULL); + Tcl_AppendResult(interp, "Key derivation failed: ", REASON(), (char *) NULL); Tcl_DecrRefCount(resultObj); } error: res = TCL_ERROR; Index: generic/tlsRand.c ================================================================== --- generic/tlsRand.c +++ generic/tlsRand.c @@ -53,11 +53,11 @@ /* Validate arg count */ if (objc < 2 || objc > 3) { Tcl_WrongNumArgs(interp, 1, objv, "?-private? length"); return TCL_ERROR; } else if (objc == 3) { - int fn; + Tcl_Size fn; if (Tcl_GetIndexFromObj(interp, objv[1], command_opts, "option", 0, &fn) != TCL_OK) { return TCL_ERROR; } } @@ -70,11 +70,11 @@ return TCL_ERROR; } /* Allocate storage for result */ resultObj = Tcl_NewObj(); - out_buf = Tcl_SetByteArrayLength(resultObj, out_len); + out_buf = Tcl_SetByteArrayLength(resultObj, (Tcl_Size) out_len); if (resultObj == NULL || out_buf == NULL) { Tcl_AppendResult(interp, "Memory allocation error", (char *) NULL); Tcl_DecrRefCount(resultObj); return TCL_ERROR; } Index: generic/tlsUtil.c ================================================================== --- generic/tlsUtil.c +++ generic/tlsUtil.c @@ -30,11 +30,11 @@ EVP_CIPHER *Util_GetCipher(Tcl_Interp *interp, Tcl_Obj *cipherObj, int no_null) { EVP_CIPHER *cipher = NULL; char *name = NULL; if (cipherObj != NULL) { - name = Tcl_GetStringFromObj(cipherObj, NULL); + name = Tcl_GetStringFromObj(cipherObj, (Tcl_Size *) NULL); #if OPENSSL_VERSION_NUMBER < 0x30000000L cipher = EVP_get_cipherbyname(name); #else cipher = EVP_CIPHER_fetch(NULL, name, NULL); #endif @@ -65,11 +65,11 @@ EVP_MD *Util_GetDigest(Tcl_Interp *interp, Tcl_Obj *digestObj, int no_null) { EVP_MD *md = NULL; char *name = NULL; if (digestObj != NULL) { - name = Tcl_GetStringFromObj(digestObj, NULL); + name = Tcl_GetStringFromObj(digestObj, (Tcl_Size *) NULL); #if OPENSSL_VERSION_NUMBER < 0x30000000L md = EVP_get_digestbyname(name); #else md = EVP_MD_fetch(NULL, name, NULL); #endif @@ -95,16 +95,18 @@ * Side effects: * None * *------------------------------------------------------------------- */ -unsigned char *Util_GetIV(Tcl_Interp *interp, Tcl_Obj *ivObj, int *len, int max, int no_null) { +unsigned char *Util_GetIV(Tcl_Interp *interp, Tcl_Obj *ivObj, Tcl_Size *len, int max, int no_null) { unsigned char *iv = NULL; *len = 0; + Tcl_Size size = 0; if (ivObj != NULL) { - iv = Tcl_GetByteArrayFromObj(ivObj, len); + iv = Tcl_GetByteArrayFromObj(ivObj, &size); + *len = (int) size; } else if (no_null) { Tcl_AppendResult(interp, "no initialization vector (IV)", (char *) NULL); return NULL; } @@ -128,11 +130,11 @@ * Side effects: * None * *------------------------------------------------------------------- */ -unsigned char *Util_GetKey(Tcl_Interp *interp, Tcl_Obj *keyObj, int *len, char *name, int max, int no_null) { +unsigned char *Util_GetKey(Tcl_Interp *interp, Tcl_Obj *keyObj, Tcl_Size *len, char *name, int max, int no_null) { unsigned char *key = NULL; *len = 0; if (keyObj != NULL) { key = Tcl_GetByteArrayFromObj(keyObj, len); @@ -167,11 +169,11 @@ EVP_MAC *Util_GetMAC(Tcl_Interp *interp, Tcl_Obj *MacObj, int no_null) { EVP_MAC *mac = NULL; char *name = NULL; if (MacObj != NULL) { - name = Tcl_GetStringFromObj(MacObj, NULL); + name = Tcl_GetStringFromObj(MacObj, (Tcl_Size *) NULL); mac = EVP_MAC_fetch(NULL, name, NULL); if (mac == NULL) { Tcl_AppendResult(interp, "invalid MAC \"", name, "\"", (char *) NULL); return NULL; } @@ -195,11 +197,11 @@ * Side effects: * None * *------------------------------------------------------------------- */ -unsigned char *Util_GetSalt(Tcl_Interp *interp, Tcl_Obj *saltObj, int *len, int max, int no_null) { +unsigned char *Util_GetSalt(Tcl_Interp *interp, Tcl_Obj *saltObj, Tcl_Size *len, int max, int no_null) { unsigned char *salt = NULL; *len = 0; if (saltObj != NULL) { salt = Tcl_GetByteArrayFromObj(saltObj, len); @@ -230,11 +232,12 @@ * Side effects: * None * *------------------------------------------------------------------- */ -unsigned char *Util_GetBinaryArray(Tcl_Interp *interp, Tcl_Obj *dataObj, int *len, char *name, int min, int max, int no_null) { +unsigned char *Util_GetBinaryArray(Tcl_Interp *interp, Tcl_Obj *dataObj, Tcl_Size *len, + char *name, Tcl_Size min, Tcl_Size max, int no_null) { unsigned char *data = NULL; *len = 0; if (dataObj != NULL) { data = Tcl_GetByteArrayFromObj(dataObj, len); Index: tests/all.tcl ================================================================== --- tests/all.tcl +++ tests/all.tcl @@ -18,11 +18,11 @@ namespace import ::tcltest::* } # Get common functions if {[file exists [file join $path common.tcl]]} { - source [file join $path common.tcl] + source -encoding utf-8 [file join $path common.tcl] } set ::tcltest::testSingleFile false set ::tcltest::testsDirectory [file dir [info script]] Index: tests/badssl.test ================================================================== --- tests/badssl.test +++ tests/badssl.test @@ -15,16 +15,11 @@ # Constraints source common.tcl # Helper functions -proc badssl {url} {set port 443 - lassign [split $url ":"] url port - if {$port eq ""} {set port 443} - set ch [tls::socket -autoservername 1 -require 1 -cafile $::cafile $url $port] - if {[catch {tls::handshake $ch} err]} {close $ch - return -code error $err} else {close $ch}} +proc badssl {url} {set port 443;lassign [split $url ":"] url port;if {$port eq ""} {set port 443};set ch [tls::socket -autoservername 1 -require 1 -cafile $::cafile $url $port];if {[catch {tls::handshake $ch} err]} {close $ch;return -code error $err} else {close $ch}} # BadSSL.com Tests test BadSSL-1.1 {1000-sans} -body { Index: tests/random.csv ================================================================== --- tests/random.csv +++ tests/random.csv @@ -6,11 +6,11 @@ Random,Example 1,,,string length [::tls::random 42],,,42,,, Random,Example 2,,,string length [::tls::random 1000],,,1000,,, Random,Private Option,,,string length [::tls::random -private 42],,,42,,, ,,,,,,,,,, command,# Random command errors,,,,,,,,, -Random Errors,Too few args,,,::tls::random,,,"wrong # args: should be ""tls::random ?-private? length""",,,1 -Random Errors,Too many args,,,::tls::random too many command line args to pass the test without an error or failing,,,"wrong # args: should be ""tls::random ?-private? length""",,,1 +Random Errors,Too few args,,,::tls::random,,,"wrong # args: should be ""::tls::random ?-private? length""",,,1 +Random Errors,Too many args,,,::tls::random too many command line args to pass the test without an error or failing,,,"wrong # args: should be ""::tls::random ?-private? length""",,,1 Random Errors,Invalid length value,,,::tls::random bogus,,,"expected integer but got ""bogus""",,,1 Random Errors,Negative length,,,::tls::random -1,,,"bad count ""-1"": must be integer >= 0",,,1 Random Errors,Invalid option,,,::tls::random -bogus 42,,,"bad option ""-bogus"": must be -private",,,1 Random Errors,Invalid length with option,,,::tls::random -private bogus,,,"expected integer but got ""bogus""",,,1 Index: tests/random.test ================================================================== --- tests/random.test +++ tests/random.test @@ -32,15 +32,15 @@ # Random command errors test Random_Errors-2.1 {Too few args} -body { ::tls::random - } -result {wrong # args: should be "tls::random ?-private? length"} -returnCodes {1} + } -result {wrong # args: should be "::tls::random ?-private? length"} -returnCodes {1} test Random_Errors-2.2 {Too many args} -body { ::tls::random too many command line args to pass the test without an error or failing - } -result {wrong # args: should be "tls::random ?-private? length"} -returnCodes {1} + } -result {wrong # args: should be "::tls::random ?-private? length"} -returnCodes {1} test Random_Errors-2.3 {Invalid length value} -body { ::tls::random bogus } -result {expected integer but got "bogus"} -returnCodes {1}