Advertisement
AnthonyCagliano

Untitled

Mar 30th, 2023
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. ; aes_gf2_mul(uint8_t *out, uint8_t *op1, uint8_t *op2);
  2. _aes_gf2_mul:
  3. ld hl, -16
  4. call ti._frameset
  5. lea de, ix - 16 ; stack mem?
  6. ld hl, (ix + 9) ; op1 (save a copy)
  7. ld bc, 16
  8. ldir ; ix - 32 = tmp = op1
  9.  
  10. ; zero out output
  11. ld de, (ix + 6) ; op 1
  12. xor a
  13. ld (de), a
  14. inc de
  15. ld hl, (ix + 6)
  16. ld bc, 15
  17. ldir
  18.  
  19. ld hl, (ix + 12) ; op2 = for bit in bits
  20. ld bc, 0
  21. ld c, 15
  22. add hl, bc ; comment out for little endian
  23. inc c
  24. .loop_op2:
  25. ld a, (hl)
  26. push hl
  27. ld b, 8
  28. .loop_bits_in_byte:
  29. rra
  30. push af
  31. sbc a,a
  32. push bc
  33. ld c,a
  34.  
  35. ; add op1 (res) + tmp
  36. ld hl, (ix + 6) ; hl = (dest)
  37. lea de, ix - 16 ; de = tmp (src)
  38. ld b, 16
  39. .loop_add:
  40. ld a, (de)
  41. and a, c
  42. xor a, (hl)
  43. ld (hl), a
  44. inc hl
  45. inc de
  46. djnz .loop_add
  47.  
  48. ; now double tmp
  49. ; lea hl, ix - 16 ; tmp in hl little endian
  50. lea hl, ix - 1 ; tmp in hl big endian
  51. ld b, 16
  52. or a ; reset carry
  53. .loop_mul2:
  54. rl (hl)
  55. ;inc hl ; little endian
  56. dec hl ; big endian
  57. djnz .loop_mul2
  58.  
  59. ; now xor with polynomial x^128 + x^7 + x^2 + x + 1
  60. ; if bit 128 set, xor LSByte with 10000111b
  61.  
  62. sbc a, a
  63. and a, 10000111b
  64. ; xor a, (ix - 16) ; little endian
  65. ; ld (ix - 16), a
  66. xor a, (ix - 1) ; big endian
  67. ld (ix - 1), a
  68.  
  69. .no_xor_poly:
  70. pop bc
  71. pop af
  72. djnz .loop_bits_in_byte
  73. pop hl
  74. ; inc hl ; little endian
  75. dec hl ; big endian
  76. dec c
  77. jr nz, .loop_op2
  78. ld sp, ix
  79. pop ix
  80. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement