code: def set_key(self, key):
          
  
          key_len = len(key)
          if key_len not in [16, 24, 32]:
              # XXX: add padding?
              raise KeyError("key must be 16, 24 or 32 bytes")
          if key_len % 4:
              # XXX: add padding?
              raise KeyError("key not a multiple of 4")
          if key_len > 32:
              # XXX: prune?
              raise KeyError("key_len > 32")
  
          self.context = TWI()
  
          key_word32 = [0] * 32
          i = 0
          while key:
              key_word32[i] = struct.unpack("<L", key[0:4])[0]
              key = key[4:]
              i += 1
  
          set_key(self.context, key_word32, key_len)
docs: Init.