This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

hardware accelerated random()


Hello, 
I wrote random generator that uses aes-ni. I generate random numbers in
groups of 16 and then use them.
On my i5 test program spend about 6.4 cycles per call. 
I put sample implementation on
http://kam.mff.cuni.cz/~ondra/rand_aes.tar.bz2

I am not cryptographer so I do not know if this ways causes significant
statistical weakness.

Relevant part follows.

aesrand:
	mov %rdi,%rax
  movdqa    (%rax),%xmm0
  movdqa  16(%rax),%xmm1
  movdqa  32(%rax),%xmm2
  movdqa  48(%rax),%xmm3

  movdqa %xmm0,%xmm4
  movdqa %xmm1,%xmm5
  movdqa %xmm2,%xmm6
  movdqa %xmm3,%xmm7

  aesenc %xmm4,%xmm0
  aesenc %xmm4,%xmm1
  aesenc %xmm4,%xmm2
  aesenc %xmm4,%xmm3

  aesenc %xmm5,%xmm0
  aesenc %xmm5,%xmm1
  aesenc %xmm5,%xmm2
  aesenc %xmm5,%xmm3

  aesenc %xmm6,%xmm0
  aesenc %xmm6,%xmm1
  aesenc %xmm6,%xmm2
  aesenc %xmm6,%xmm3

  aesenc %xmm7,%xmm0
  aesenc %xmm7,%xmm1
  aesenc %xmm7,%xmm2
  aesenc %xmm7,%xmm3

  movdqa %xmm0,   (%rax)
  movdqa %xmm1, 16(%rax)
  movdqa %xmm2, 32(%rax)
  movdqa %xmm3, 48(%rax)

	ret



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]