@@ -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; }