Skip to contentSkip to conversation

Add RNG support to AF_ALG

PATCH New Neil Horman 2 participants 7 messages Dec 13, 2010 – Jan 21, 2011 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add RNG support to AF_ALG

This patch enhances the AF_ALG protocol family to include support for random number generator algorithms. With this enhancment, users of the AF_ALG protocol can now bind sockets to instances of the various RNG algorithms available to the kernel. For those RNG's that support it, instances can be reseeded using the SETKEY socket option within the AF_ALG socket family. Like with hashes and ciphers, only the intially created socket allows seeding, and only child sockets retured via accept may return random data. Sending data on RNG instances is prohibited, only receiving RNG data is possible.

Tested successfully using NIST provided RNG vectors by myself:

CC Herbert Xu <[email protected]>
CC "David S. Miller" <[email protected]>
---
 crypto/Kconfig     |    9 +++
 crypto/Makefile    |    1 +
 crypto/algif_rng.c |  197 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 207 insertions(+), 0 deletions(-)
 create mode 100644 crypto/algif_rng.c
crypto/Kconfig +9 -0
index 96b0e55..ea448ca 100644
@@ -864,6 +864,15 @@ config CRYPTO_USER_API_SKCIPHER
 	  This option enables the user-spaces interface for symmetric
 	  key cipher algorithms.
 
+config CRYPTO_USER_API_RNG
+	tristate "User-space interface for Random Number Generator algorithms"
+	depends on NET
+	select CRYPTO_ANSI_CPRNG
+	select CRYPTO_USER_API
+	help
+	  This option enables the user-space interface for random number
+	  generation algorithms.
+
 source "drivers/crypto/Kconfig"
 
 endif	# if CRYPTO
crypto/Makefile +1 -0
index e9a399c..8868555 100644
@@ -88,6 +88,7 @@ obj-$(CONFIG_CRYPTO_GHASH) += ghash-generic.o
 obj-$(CONFIG_CRYPTO_USER_API) += af_alg.o
 obj-$(CONFIG_CRYPTO_USER_API_HASH) += algif_hash.o
 obj-$(CONFIG_CRYPTO_USER_API_SKCIPHER) += algif_skcipher.o
+obj-$(CONFIG_CRYPTO_USER_API_RNG) += algif_rng.o
 
 #
 # generic algorithms and the async_tx api
crypto/algif_rng.c new file +197 -0

197 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 1/1 Add RNG support to AF_ALG (v2)

Change notes:
Changed rng_rcvmsg to allocate a fixed size maximum temp block to store rng data when recvmsg is called. This should prevent malicious DoS from user space by tring to receive obscene amounts of random data in one call. Instead now we loop using the same block of data and copy it incrementally to the user space buffer using memcpy_toiovecend

Also changed the accept routine to only allocate a new rng, and not store the seed value separately, simplifying the code somewhat. also now we memset the parent sockets seed value to zero on free to hide the seed from intruders.

Summary:
This patch enhances the AF_ALG protocol family to include support for random number generator algorithms. With this enhancment, users of the AF_ALG protocol can now bind sockets to instances of the various RNG algorithms available to the kernel. For those RNG's that support it, instances can be reseeded using the SETKEY socket option within the AF_ALG socket family. Like with hashes and ciphers, only the intially created socket allows seeding, and only child sockets retured via accept may return random data. Sending data on RNG instances is prohibited, only receiving RNG data is possible.

Tested successfully using NIST provided RNG vectors by myself:

CC Herbert Xu <[email protected]>
CC "David S. Miller" <[email protected]>
---
 crypto/Kconfig     |    9 ++
 crypto/Makefile    |    1 +
 crypto/algif_rng.c |  212 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 222 insertions(+), 0 deletions(-)
 create mode 100644 crypto/algif_rng.c
crypto/Kconfig +9 -0
index 96b0e55..ea448ca 100644
@@ -864,6 +864,15 @@ config CRYPTO_USER_API_SKCIPHER
 	  This option enables the user-spaces interface for symmetric
 	  key cipher algorithms.
 
+config CRYPTO_USER_API_RNG
+	tristate "User-space interface for Random Number Generator algorithms"
+	depends on NET
+	select CRYPTO_ANSI_CPRNG
+	select CRYPTO_USER_API
+	help
+	  This option enables the user-space interface for random number
+	  generation algorithms.
+
 source "drivers/crypto/Kconfig"
 
 endif	# if CRYPTO
crypto/Makefile +1 -0
index e9a399c..8868555 100644
@@ -88,6 +88,7 @@ obj-$(CONFIG_CRYPTO_GHASH) += ghash-generic.o
 obj-$(CONFIG_CRYPTO_USER_API) += af_alg.o
 obj-$(CONFIG_CRYPTO_USER_API_HASH) += algif_hash.o
 obj-$(CONFIG_CRYPTO_USER_API_SKCIPHER) += algif_skcipher.o
+obj-$(CONFIG_CRYPTO_USER_API_RNG) += algif_rng.o
 
 #
 # generic algorithms and the async_tx api
crypto/algif_rng.c new file +212 -0

212 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#2 lore raw

Re: [PATCH] Add RNG support to AF_ALG (v2)

Quoted 21 lines · Neil Horman

Change notes:
Changed rng_rcvmsg to allocate a fixed size maximum temp block to store rng data when recvmsg is called. This should prevent malicious DoS from user space by tring to receive obscene amounts of random data in one call. Instead now we loop using the same block of data and copy it incrementally to the user space buffer using memcpy_toiovecend

Also changed the accept routine to only allocate a new rng, and not store the seed value separately, simplifying the code somewhat. also now we memset the parent sockets seed value to zero on free to hide the seed from intruders.

Summary:
This patch enhances the AF_ALG protocol family to include support for random number generator algorithms. With this enhancment, users of the AF_ALG protocol can now bind sockets to instances of the various RNG algorithms available to the kernel. For those RNG's that support it, instances can be reseeded using the SETKEY socket option within the AF_ALG socket family. Like with hashes and ciphers, only the intially created socket allows seeding, and only child sockets retured via accept may return random data. Sending data on RNG instances is prohibited, only receiving RNG data is possible.

Quoted 4 lines

Tested successfully using NIST provided RNG vectors by myself:

CC Herbert Xu <[email protected]>
CC "David S. Miller" <[email protected]>

Herbert, Sorry to bug you about this, but are you still planning on pulling this now that Linus has the infrastructure scheduled for 2.6.38?

Neil

maintainer
#3 lore raw

Re: [PATCH] Add RNG support to AF_ALG (v2)

Quoted 3 lines · Neil Horman

Herbert, Sorry to bug you about this, but are you still planning on pulling this now that Linus has the infrastructure scheduled for 2.6.38?

I think it's best if we leave this out for now, unless we can come up with some way of merging this with the hardware RNG interface so that we are not duplicating an existing user interface.

Could we perhaps merge this with the HWRNG interface somehow? Or maybe we should just expose ansi_cprng (I presume you only need that) through the hwrng interface?

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#4 lore raw

Re: [PATCH] Add RNG support to AF_ALG (v2)

Quoted 9 lines · Herbert Xu
Quoted 3 lines · Neil Horman

Herbert, Sorry to bug you about this, but are you still planning on pulling this now that Linus has the infrastructure scheduled for 2.6.38?

I think it's best if we leave this out for now, unless we can come up with some way of merging this with the hardware RNG interface so that we are not duplicating an existing user interface.

I take your point, but I'm not certain I agree that we are duplicating an existing user interface. A cursory glance would say that we are, but /dev/random and /dev/urandom really just provide access to the kernels entropy pools, whereas the AF_ALG provides access to instances of any RNG the kernel has to offer as well as the key management services that AF_ALG has, which I think is adventageous, given that the CPRNG requires keying to work properly.

Quoted 1 line

Could we perhaps merge this with the HWRNG interface somehow?

We could certainly, add an ioctl to place /dev/[u]random in a cprng mode, and another to allow key setting/resets/etc, but that seems fairly limiting in that only one instace of a cprng could be accessed at a time.

Quoted 3 lines

Or maybe we should just expose ansi_cprng (I presume you only need that) through the hwrng interface?

Again, we could, but that doesn't seem wise if:
1) A user is expecting truly random data
2) A user needs to truly have predicitbility of their random number set (if they're using the cprng, multiple un-cordinated users breaks the ability to predict the rng data).

Another alternative (just off the top of my head), might be to eliminate the hwrng interface in the kernel entirely, and replace it with the AF_ALG based interface. People requiring access to /dev/random until their applications can be migrated could still access /dev/[u]random via a user space daemon that opens 2 unix sockets, binds them to /dev/[u]random, and proxies them to two AF_ALG sockets connected to the blocking and non-blocking entropy pools in the kernel.

Not saying thats a great idea mind, just brainstorming ways we can eliminate interface duplication without restricting the CPRNG to a character based interface, when AF_ALG provides it so much more.
Neil

Quoted 10 lines

Thanks,

Signature · 7 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#5 lore raw

Re: [PATCH] Add RNG support to AF_ALG (v2)

Quoted 7 lines · Neil Horman

I take your point, but I'm not certain I agree that we are duplicating an existing user interface. A cursory glance would say that we are, but /dev/random and /dev/urandom really just provide access to the kernels entropy pools, whereas the AF_ALG provides access to instances of any RNG the kernel has to offer as well as the key management services that AF_ALG has, which I think is adventageous, given that the CPRNG requires keying to work properly.

I'm not talking about /dev/random, I'm talking the hwrng interface in drivers/char/hwrng.

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#6 lore raw

Re: [PATCH] Add RNG support to AF_ALG (v2)

Quoted 9 lines · Herbert Xu
Quoted 7 lines · Neil Horman

I take your point, but I'm not certain I agree that we are duplicating an existing user interface. A cursory glance would say that we are, but /dev/random and /dev/urandom really just provide access to the kernels entropy pools, whereas the AF_ALG provides access to instances of any RNG the kernel has to offer as well as the key management services that AF_ALG has, which I think is adventageous, given that the CPRNG requires keying to work properly.

Quoted 3 lines

I'm not talking about /dev/random, I'm talking the hwrng interface in drivers/char/hwrng.

Doh! I'm sorry, that was stupid of me. Yes that makes alot more sense. I'll try another pass, adding the cprng to that interface instead.

Thanks!
Neil

Quoted 6 lines

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt