Description of the control system used in the driver
of a crypt-channel to decide about its actions upon
output-requests.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

General background
------------------

We have to deal with:

-	Statically different buffersizes, smaller or greater
	than a block of the used cryptosystem.

-	Buffersizes not being a multiple of the blocksize.

-	Buffersizes dynamically changing between calls to the
	driver function.

Because Tcl_Write absorbs its input completely under all
circumstances there is no problem with partially executed
writes.  Only incomplete blocks in the input have to be
considered.



Implementation basics
---------------------

The driver uses an internal buffer to hold already encrypted
data waiting for writing into the underlying channel.

The buffer is divided into 2 segments, with the border dynamically
changing.  Segment 1 contains all data already encrypted, but waiting
for writing into the underlying channel. Segment 2 contain
unencrypted data waiting for encryption.


State information therefore contains:

-	The buffer, its actual and maximal length.
-	The number of bytes waiting for writing into the
	underlying channel.

Properties are:

	#'waiting for write ' <= actual length <= maximal length


Although desirable, the buffer is NOT an instance of Tcl_DString.
This type is unable to handle data with embedded zeros.


Decision scheme
---------------

Upon a write request from the generic layer the following
actions are executed:

1)	Try to write as much waiting encrypted data as possible
	into the underlying channel.
2)	Remove everything written from the buffer.
3)	Append the new data to the buffer.
4)	Encrypt as much as possible.
