|
A while back, I reported that while I had been quite happy with
Crypto++ 4.2, it didn't work on AMD64, and while I was able to convert
to 5.2.1, the increase in module interdependencies pushed up the size
of my product rpm by factor of three or four, which was unacceptable.
A number of people contacted me off list and asked to hear when I found
a solution. I'm a database guy with both a commercial product and an involvement in an open source database project. Database systems often need DES for password managers, SHA for password encoding and manifests, PKCS for digital signatures and key exchange, and eventually AES for link encryption. At the beginning of the crypto library audition process, I decided I needed a generic crypto API to mask the differences between the various library APIs. The scheme I came up with is probably more interesting (and potentially important) than the library search itself, so I thought I would report it here. At the end, I'll get back to the search results. The API revolves around of the idea of a "transformation" that transforms data from one form to another. The transform library is a set of polymorphic C++ classes that implement the abstract base class: class TransformThe semantics are simple. The method "getLength" returns a reliable upper bound of the final length. The method "get" must return all available bytes up to the size of the given buffer, returning zero when no bytes are remaining. The method "reset" prepares for another data cycle, resetting transient state but retaining keys and modes. Each transformation is independent -- none knows the implementation of any other. Transforms are designed to be daisy chained, each calling another transform for input data. While all transforms export the same base API, they can be loosely grouped into source transforms (StringTransform, FileTransform, BlobTransform), encoders (Base64Transform, HexTransform, DESKeyTransform), and encrypting transforms (DESTransform, RSATransform, SHATransform, etc). The main difference between the types are in their constructors, where source transforms get a character string or byte array, encoders get a source transform and an encode/decode flag, while encrypting transforms get a source transform and an encryption type or mode. There are also a number of template transforms to aid the process of forming daisy chains. The EncryptTransform, for sample, takes as template parameters the name of a source class, an encryption class, and an encoding class and is, in essence, a composite transform. Encryption transforms general export ad hoc methods for key specification, usually as transforms. These methods are necessarily outside of the base class. A couple of examples: StringTransform source ("Hello, world");or, the equivalent EncryptTransform<StringTransform,SHATransform,HexTransform> trans ("Hello, world");A more complex example: EncodeTransform<FileTransform,DESKeyTransform> key ("secret.key");During the process of library implementation, I cut all of the crypto code in my commercial system over to transforms. Among the benefits:
As for the library search, there are a surprising number of crypto libraries out there. Some were ruled by license, since I need a library embeddable in a commercial product. Others were rules out by language (C or C++ is a requirements; Delphi need not apply). The libraries I looked at in depth were:
If anyone is interesting in chatting about the Transform Library, please contact me here or off list. If there is significant interest, I'll set up a list server. |
- Re: Generic Crypto API Jim Starkey
- Re: Generic Crypto API sam wun
- Re: Generic Crypto API Jim Starkey
