You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.9 KiB

  1. // Copyright (c) 2016 Andreas Auernhammer. All rights reserved.
  2. // Use of this source code is governed by a license that can be
  3. // found in the LICENSE file.
  4. // +build !amd64
  5. package threefish
  6. func bytesToBlock256(block *[4]uint64, src []byte) {
  7. for i := range block {
  8. j := i * 8
  9. block[i] = uint64(src[j]) | uint64(src[j+1])<<8 | uint64(src[j+2])<<16 | uint64(src[j+3])<<24 |
  10. uint64(src[j+4])<<32 | uint64(src[j+5])<<40 | uint64(src[j+6])<<48 | uint64(src[j+7])<<56
  11. }
  12. }
  13. func block256ToBytes(dst []byte, block *[4]uint64) {
  14. for i, v := range block {
  15. j := i * 8
  16. dst[j] = byte(v)
  17. dst[j+1] = byte(v >> 8)
  18. dst[j+2] = byte(v >> 16)
  19. dst[j+3] = byte(v >> 24)
  20. dst[j+4] = byte(v >> 32)
  21. dst[j+5] = byte(v >> 40)
  22. dst[j+6] = byte(v >> 48)
  23. dst[j+7] = byte(v >> 56)
  24. }
  25. }
  26. func bytesToBlock512(block *[8]uint64, src []byte) {
  27. for i := range block {
  28. j := i * 8
  29. block[i] = uint64(src[j]) | uint64(src[j+1])<<8 | uint64(src[j+2])<<16 | uint64(src[j+3])<<24 |
  30. uint64(src[j+4])<<32 | uint64(src[j+5])<<40 | uint64(src[j+6])<<48 | uint64(src[j+7])<<56
  31. }
  32. }
  33. func block512ToBytes(dst []byte, block *[8]uint64) {
  34. for i, v := range block {
  35. j := i * 8
  36. dst[j] = byte(v)
  37. dst[j+1] = byte(v >> 8)
  38. dst[j+2] = byte(v >> 16)
  39. dst[j+3] = byte(v >> 24)
  40. dst[j+4] = byte(v >> 32)
  41. dst[j+5] = byte(v >> 40)
  42. dst[j+6] = byte(v >> 48)
  43. dst[j+7] = byte(v >> 56)
  44. }
  45. }
  46. func bytesToBlock1024(block *[16]uint64, src []byte) {
  47. for i := range block {
  48. j := i * 8
  49. block[i] = uint64(src[j]) | uint64(src[j+1])<<8 | uint64(src[j+2])<<16 | uint64(src[j+3])<<24 |
  50. uint64(src[j+4])<<32 | uint64(src[j+5])<<40 | uint64(src[j+6])<<48 | uint64(src[j+7])<<56
  51. }
  52. }
  53. func block1024ToBytes(dst []byte, block *[16]uint64) {
  54. for i, v := range block {
  55. j := i * 8
  56. dst[j] = byte(v)
  57. dst[j+1] = byte(v >> 8)
  58. dst[j+2] = byte(v >> 16)
  59. dst[j+3] = byte(v >> 24)
  60. dst[j+4] = byte(v >> 32)
  61. dst[j+5] = byte(v >> 40)
  62. dst[j+6] = byte(v >> 48)
  63. dst[j+7] = byte(v >> 56)
  64. }
  65. }