Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

76 rader
2.3 KiB

  1. #!/usr/bin/env perl
  2. # Copyright (c) 2015, Google Inc.
  3. #
  4. # Permission to use, copy, modify, and/or distribute this software for any
  5. # purpose with or without fee is hereby granted, provided that the above
  6. # copyright notice and this permission notice appear in all copies.
  7. #
  8. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  15. $flavour = shift;
  16. $output = shift;
  17. if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
  18. $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
  19. ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
  20. die "can't locate x86_64-xlate.pl";
  21. open OUT,"| \"$^X\" $xlate $flavour $output";
  22. *STDOUT=*OUT;
  23. print<<___;
  24. .text
  25. # CRYPTO_rdrand writes eight bytes of random data from the hardware RNG to
  26. # |out|. It returns one on success or zero on hardware failure.
  27. # int CRYPTO_rdrand(uint8_t out[8]);
  28. .globl CRYPTO_rdrand
  29. .type CRYPTO_rdrand,\@function,1
  30. .align 16
  31. CRYPTO_rdrand:
  32. xorq %rax, %rax
  33. # This is rdrand %rcx. It sets rcx to a random value and sets the carry
  34. # flag on success.
  35. .byte 0x48, 0x0f, 0xc7, 0xf1
  36. # An add-with-carry of zero effectively sets %rax to the carry flag.
  37. adcq %rax, %rax
  38. movq %rcx, 0(%rdi)
  39. retq
  40. # CRYPTO_rdrand_multiple8_buf fills |len| bytes at |buf| with random data from
  41. # the hardware RNG. The |len| argument must be a multiple of eight. It returns
  42. # one on success and zero on hardware failure.
  43. # int CRYPTO_rdrand_multiple8_buf(uint8_t *buf, size_t len);
  44. .globl CRYPTO_rdrand_multiple8_buf
  45. .type CRYPTO_rdrand_multiple8_buf,\@function,2
  46. .align 16
  47. CRYPTO_rdrand_multiple8_buf:
  48. test %rsi, %rsi
  49. jz .Lout
  50. movq \$8, %rdx
  51. .Lloop:
  52. # This is rdrand %rcx. It sets rcx to a random value and sets the carry
  53. # flag on success.
  54. .byte 0x48, 0x0f, 0xc7, 0xf1
  55. jnc .Lerr
  56. movq %rcx, 0(%rdi)
  57. addq %rdx, %rdi
  58. subq %rdx, %rsi
  59. jnz .Lloop
  60. .Lout:
  61. movq \$1, %rax
  62. retq
  63. .Lerr:
  64. xorq %rax, %rax
  65. retq
  66. ___
  67. close STDOUT; # flush