jump to navigation

linux kernel source tracing (crypto) part 1 March 28, 2007

Posted by TSAI HONG-BIN in Linux.
trackback

If you check ~linux/Documentation/crypto, you’ll find a api-intro.txt. It’s a good place to start. In the document you’re told that crypto API, “ITSELF”, is divided into 3 different layers, transform API, transform ops and algorithm API. Further information? please read the source (ya, the document guide you to tcrypt.c)… or my diary-style post =P

Let’s start from ~linux/crypto/tcrypt.c

tcrypt is designed as a module, so, if you want to see how it works by running it, a correct kernel configuration is required. Check either Cryptographic options -> Testing module is marked [M], or grep .config for CONFIG_CRYPTO_TEST=m.

I prefer to follow the source, so I start from digging into tcrypt.c init function. It merely calls do_test(), and do_test() calls test_hash(), test_cipher()…etc. one after one. After checking the definition of test_cipher(), resided in tcrypt.c as well, you find that the first suspect function call in test_cipher() is crypto_alloc_blkcipher(). Remember the lxr website I mentioned? (http://lxr.linux.no/) Now you see that crypto_alloc_blkcipher() is defined in ~linux/include/linux/crypto.h. The return value is the return of another function call __crypto_blkcipher_cast (crypto_alloc_base()). Be good, follow me on this path of no return. Check the definition of crypto_alloc_base(), it’s in ~linux/crypto/api.c, don’t be afraid, the function has less than 40 lines. Check the first thing it does, crypto_alg_mod_lookup(). Oh well, it first checks if the crypto-algorithm module is loaded. (literally, it says so.) If there is an error returned, it goes to error handle process. If the algorithm module is located, it the goes to __crypto_alloc_tfm(). By seeing “__” prefix you must have known that this function is invoked privately.

Without digging into the function calls within __crypto_alloc_tfm(), you may have an instinct that this function is doing nothing more than initializing the object crypto_tfm. If the object is successfully initialized, it then returns a crypto_tfm pointer.

Let’s take a short break and take a look at what we have treaded.

in tcrypt.c: init() –> do_test() –> test_cipher() –> crypto_alloc_blkcipher()

crypto_alloc_blkcipher() is defined in crypto.h and its return value is the return of function __crypto_blkcipher_cast (crypto_alloc_base()). the return value of crypto_alloc_base is a crypto_tfm (if no error,) so now let’s check what is __crypto_blkcipher_cast() doing. Remember, a “__” prefix means it is defined and invoked locally. The definition of __crypto_blkcipher_cast() is nothing more than casting structure type crypto_tfm to crypto_blkcipher. So, you may want to see how these structs are defined.

[TBC]

Advertisements

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: