samedi 4 novembre 2017

How to structure Crypto library

I'm trying to write my own Crypto library in C++, but I'm having some trouble with the OOP-side of things.

I'm trying to structure my library in a way that allows optimal modularity and reusability, while still being easy-to-use for anyone that, well, uses the library.

I've already implemented AES (128, 192 and 256) and I'm able to correctly encrypt and decrypt data (I wrote some unit tests that use NIST's ECB test vectors)

Right now I'm trying to get AES to work in a chained matter. (So Proper ECB, CBC, CFB, OFB, ...)

I'm at a loss on how to structure my library in a way that makes it easy-to-use for an "end-user" (most likely just me in other projects).

Right now, this is how I have it set up:

I have a CipherFactory class that has a static method createBlockCipher, this method takes in the name of a block cipher as a string and returns a BlockCipher object that can be used for encryption and decryption of single blocks.

I have a BlockCipher class that is basically a super-class to all block ciphers I implement (Right now just AES, I will probably add some more along the way). The BlockCipher class provides some getters for getting blocksize, keysize and the algorithm's name. It also has virtual encryption and decryption methods that throw a NotImplemented exception when called, to prevent someone from trying to encrypt anything with this fictious super-class.

Then I have an AES class that inherits from the BlockCipher class and implements its encryption and decryption methods.

I guess what I'm looking for is some UML class-diagrams, design patterns or general advice that allows me to implement chaining modes in an elegant way.

I've already had a look at Crypto++ but their documentation and code looks rather cryptic to me (How ironic!).

(For those of you that aren't that knowledgable in the crypto department but are good with OOAD: http://ift.tt/2A6KiK0)

Disclaimer: I know that DIY-crypto is a bad idea most (if not all) of the time, I'm not planning on encrypting anything serious with it, this is just a personal project.

Aucun commentaire:

Enregistrer un commentaire