parameters: (self, factory, nonce, mac_len, cipher_params)
docstring: The block size of the underlying cipher, in bytes.
docstring_summary: The block size of the underlying cipher, in bytes.
docstring_tokens: The block size of the underlying cipher in bytes .
function: def __init__(self, factory, nonce, mac_len, cipher_params):
  
          if factory.block_size != 16:
              raise ValueError("OCB mode is only available for ciphers"
                               " that operate on 128 bits blocks")
  
          self.block_size = 16
          """The block size of the underlying cipher, in bytes."""
  
          self.nonce = _copy_bytes(None, None, nonce)
          """Nonce used for this session."""
          if len(nonce) not in range(1, 16):
              raise ValueError("Nonce must be at most 15 bytes long")
          if not is_buffer(nonce):
              raise TypeError("Nonce must be bytes, bytearray or memoryview")
  
          self._mac_len = mac_len
          if not 8 <= mac_len <= 16:
              raise ValueError("MAC tag must be between 8 and 16 bytes long")
  
          # Cache for MAC tag
          self._mac_tag = None
  
          # Cache for unaligned associated data
          self._cache_A = b""
  
          # Cache for unaligned ciphertext/plaintext
          self._cache_P = b""
  
          # Allowed transitions after initialization
          self._next = [self.update, self.encrypt, self.decrypt,
                        self.digest, self.verify]
  
          # Compute Offset_0
          params_without_key = dict(cipher_params)
          key = params_without_key.pop("key")
          nonce = (struct.pack('B', self._mac_len << 4 & 0xFF) +
                   b'\x00' * (14 - len(nonce)) +
                   b'\x01' + self.nonce)
  
          bottom_bits = bord(nonce[15]) & 0x3F    # 6 bits, 0..63
          top_bits = bord(nonce[15]) & 0xC0       # 2 bits
  
          ktop_cipher = factory.new(key,
                                    factory.MODE_ECB,
                                    **params_without_key)
          ktop = ktop_cipher.encrypt(struct.pack('15sB',
                                                 nonce[:15],
                                                 top_bits))
  
          stretch = ktop + strxor(ktop[:8], ktop[1:9])    # 192 bits
          offset_0 = long_to_bytes(bytes_to_long(stretch) >>
                                   (64 - bottom_bits), 24)[8:]
  
          # Create low-level cipher instance
          raw_cipher = factory._create_base_cipher(cipher_params)
          if cipher_params:
              raise TypeError("Unknown keywords: " + str(cipher_params))
  
          self._state = VoidPointer()
          result = _raw_ocb_lib.OCB_start_operation(raw_cipher.get(),
                                                    offset_0,
                                                    c_size_t(len(offset_0)),
                                                    self._state.address_of())
          if result:
              raise ValueError("Error %d while instantiating the OCB mode"
                               % result)
  
          # Ensure that object disposal of this Python object will (eventually)
          # free the memory allocated by the raw library for the cipher mode
          self._state = SmartPointer(self._state.get(),
                                     _raw_ocb_lib.OCB_stop_operation)
  
          # Memory allocated for the underlying block cipher is now owed
          # by the cipher mode
          raw_cipher.release()
function_tokens: def __init__ ( self , factory , nonce , mac_len , cipher_params ) : if factory . block_size != 16 : raise ValueError ( "OCB mode is only available for ciphers" " that operate on 128 bits blocks" ) self . block_size = 16 self . nonce = _copy_bytes ( None , None , nonce ) """Nonce used for this session.""" if len ( nonce ) not in range ( 1 , 16 ) : raise ValueError ( "Nonce must be at most 15 bytes long" ) if not is_buffer ( nonce ) : raise TypeError ( "Nonce must be bytes, bytearray or memoryview" ) self . _mac_len = mac_len if not 8 <= mac_len <= 16 : raise ValueError ( "MAC tag must be between 8 and 16 bytes long" ) # Cache for MAC tag self . _mac_tag = None # Cache for unaligned associated data self . _cache_A = b"" # Cache for unaligned ciphertext/plaintext self . _cache_P = b"" # Allowed transitions after initialization self . _next = [ self . update , self . encrypt , self . decrypt , self . digest , self . verify ] # Compute Offset_0 params_without_key = dict ( cipher_params ) key = params_without_key . pop ( "key" ) nonce = ( struct . pack ( 'B' , self . _mac_len << 4 & 0xFF ) + b'\x00' * ( 14 - len ( nonce ) ) + b'\x01' + self . nonce ) bottom_bits = bord ( nonce [ 15 ] ) & 0x3F # 6 bits, 0..63 top_bits = bord ( nonce [ 15 ] ) & 0xC0 # 2 bits ktop_cipher = factory . new ( key , factory . MODE_ECB , * * params_without_key ) ktop = ktop_cipher . encrypt ( struct . pack ( '15sB' , nonce [ : 15 ] , top_bits ) ) stretch = ktop + strxor ( ktop [ : 8 ] , ktop [ 1 : 9 ] ) # 192 bits offset_0 = long_to_bytes ( bytes_to_long ( stretch ) >> ( 64 - bottom_bits ) , 24 ) [ 8 : ] # Create low-level cipher instance raw_cipher = factory . _create_base_cipher ( cipher_params ) if cipher_params : raise TypeError ( "Unknown keywords: " + str ( cipher_params ) ) self . _state = VoidPointer ( ) result = _raw_ocb_lib . OCB_start_operation ( raw_cipher . get ( ) , offset_0 , c_size_t ( len ( offset_0 ) ) , self . _state . address_of ( ) ) if result : raise ValueError ( "Error %d while instantiating the OCB mode" % result ) # Ensure that object disposal of this Python object will (eventually) # free the memory allocated by the raw library for the cipher mode self . _state = SmartPointer ( self . _state . get ( ) , _raw_ocb_lib . OCB_stop_operation ) # Memory allocated for the underlying block cipher is now owed # by the cipher mode raw_cipher . release ( )