/Compiler/GC/instructions.py

https://github.com/KULeuven-COSIC/SCALE-MAMBA
Python | 146 lines | 112 code | 30 blank | 4 comment | 0 complexity | 4cab4bb5de0ac66e1e8cf8453330cecb MD5 | raw file
  1. import Compiler.instructions_base as base
  2. import Compiler.instructions as spdz
  3. import Compiler.tools as tools
  4. import collections
  5. import itertools
  6. class SecretBitsAF(base.RegisterArgFormat):
  7. reg_type = 'sb'
  8. class ClearBitsAF(base.RegisterArgFormat):
  9. reg_type = 'cb'
  10. base.ArgFormats['sb'] = SecretBitsAF
  11. base.ArgFormats['sbw'] = SecretBitsAF
  12. base.ArgFormats['cb'] = ClearBitsAF
  13. base.ArgFormats['cbw'] = ClearBitsAF
  14. opcodes = dict(
  15. XORS = 0x200,
  16. XORM = 0x201,
  17. ANDRS = 0x202,
  18. BITDECS = 0x203,
  19. BITCOMS = 0x204,
  20. CONVSINT = 0x205,
  21. LDMSDI = 0x206,
  22. STMSDI = 0x207,
  23. LDMSD = 0x208,
  24. STMSD = 0x209,
  25. XORCI = 0x210,
  26. BITDECC = 0x211,
  27. CONVCINT = 0x213,
  28. REVEAL = 0x214,
  29. )
  30. class xors(base.Instruction):
  31. code = opcodes['XORS']
  32. arg_format = ['int','sbw','sb','sb']
  33. class xorm(base.Instruction):
  34. code = opcodes['XORM']
  35. arg_format = ['int','sbw','sb','cb']
  36. class xorci(base.Instruction):
  37. code = opcodes['XORCI']
  38. arg_format = ['cbw','cb','int']
  39. class andrs(base.Instruction):
  40. code = opcodes['ANDRS']
  41. arg_format = ['int','sbw','sb','sb']
  42. class mulci(base.Instruction):
  43. code = base.opcodes['MULCI']
  44. arg_format = ['cbw','cb','int']
  45. class bitdecs(base.VarArgsInstruction):
  46. code = opcodes['BITDECS']
  47. arg_format = tools.chain(['sb'], itertools.repeat('sbw'))
  48. class bitcoms(base.VarArgsInstruction):
  49. code = opcodes['BITCOMS']
  50. arg_format = tools.chain(['sbw'], itertools.repeat('sb'))
  51. class bitdecc(base.VarArgsInstruction):
  52. code = opcodes['BITDECC']
  53. arg_format = tools.chain(['cb'], itertools.repeat('cbw'))
  54. class shrci(base.Instruction):
  55. code = base.opcodes['SHRCI']
  56. arg_format = ['cbw','cb','int']
  57. class ldsi(base.Instruction):
  58. code = base.opcodes['LDSI']
  59. arg_format = ['sbw','i']
  60. class ldms(base.DirectMemoryInstruction, base.ReadMemoryInstruction):
  61. code = base.opcodes['LDMS']
  62. arg_format = ['sbw','int']
  63. class stms(base.DirectMemoryWriteInstruction):
  64. code = base.opcodes['STMS']
  65. arg_format = ['sb','int']
  66. # def __init__(self, *args, **kwargs):
  67. # super(type(self), self).__init__(*args, **kwargs)
  68. # import inspect
  69. # self.caller = [frame[1:] for frame in inspect.stack()[1:]]
  70. class ldmc(base.DirectMemoryInstruction, base.ReadMemoryInstruction):
  71. code = base.opcodes['LDMC']
  72. arg_format = ['cbw','int']
  73. class stmc(base.DirectMemoryWriteInstruction):
  74. code = base.opcodes['STMC']
  75. arg_format = ['cb','int']
  76. class ldmsi(base.ReadMemoryInstruction):
  77. code = base.opcodes['LDMSI']
  78. arg_format = ['sbw','r']
  79. class stmsi(base.WriteMemoryInstruction):
  80. code = base.opcodes['STMSI']
  81. arg_format = ['sb','r']
  82. class ldmsdi(base.ReadMemoryInstruction):
  83. code = opcodes['LDMSDI']
  84. arg_format = ['sbw','cb']
  85. class stmsdi(base.WriteMemoryInstruction):
  86. code = opcodes['STMSDI']
  87. arg_format = ['sb','cb']
  88. class ldmsd(base.ReadMemoryInstruction):
  89. code = opcodes['LDMSD']
  90. arg_format = ['sbw','int']
  91. class stmsd(base.WriteMemoryInstruction):
  92. code = opcodes['STMSD']
  93. arg_format = ['sb','int']
  94. class convsint(base.Instruction):
  95. code = opcodes['CONVSINT']
  96. arg_format = ['sbw','r']
  97. class convcint(base.Instruction):
  98. code = opcodes['CONVCINT']
  99. arg_format = ['cbw','r']
  100. class movs(base.Instruction):
  101. code = base.opcodes['MOVS']
  102. arg_format = ['sbw','sb']
  103. class bit(base.Instruction):
  104. code = base.opcodes['BIT']
  105. arg_format = ['sbw']
  106. class reveal(base.Instruction):
  107. code = opcodes['REVEAL']
  108. arg_format = ['int','cbw','sb']
  109. class print_reg(base.IOInstruction):
  110. code = base.opcodes['PRINTREG']
  111. arg_format = ['cb','i']
  112. def __init__(self, reg, comment=''):
  113. super(print_reg, self).__init__(reg, self.str_to_int(comment))
  114. class print_reg_plain(base.IOInstruction):
  115. code = base.opcodes['PRINTREGPLAIN']
  116. arg_format = ['cb']