How to use the pyrtl.WireVector function in pyrtl

To help you get started, we’ve selected a few pyrtl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github UCSBarchlab / PyRTL / tests / test_helperfuncs.py View on Github external
def test_no_bits_to_update(self):
        a = pyrtl.WireVector(name='a', bitwidth=3)
        b = pyrtl.WireVector(name='b', bitwidth=3)
        with self.assertRaises(pyrtl.PyrtlError):
            o = pyrtl.bitfield_update(a,1,1,b,truncating=True)
github UCSBarchlab / PyRTL / research / aes / aes_encryption.py View on Github external
def aes_encryption(plaintext, key):
	""" Main function of the AES encryption algorithm.

	Inputs: 128-bit plaintext.
			128-bit key.

	Output: 128-bit ciphertext.
	"""
	# Wire declarations.
	temp_1 = pyrtl.WireVector(bitwidth=128, name='temp_1')
	temp_2 = pyrtl.WireVector(bitwidth=128, name='temp_2')
	temp_3 = pyrtl.WireVector(bitwidth=128, name='temp_3')
	temp_4 = pyrtl.WireVector(bitwidth=128, name='temp_4')
	temp_5 = pyrtl.WireVector(bitwidth=128, name='temp_5')
	temp_6 = pyrtl.WireVector(bitwidth=128, name='temp_6')
	temp_7 = pyrtl.WireVector(bitwidth=128, name='temp_7')
	temp_8 = pyrtl.WireVector(bitwidth=128, name='temp_8')
	temp_9 = pyrtl.WireVector(bitwidth=128, name='temp_9')
	temp_10 = pyrtl.WireVector(bitwidth=128, name='temp_10')
	temp_11 = pyrtl.WireVector(bitwidth=128, name='temp_11')
	temp_12 = pyrtl.WireVector(bitwidth=128, name='temp_12')
	temp_13 = pyrtl.WireVector(bitwidth=128, name='temp_13')
	temp_14 = pyrtl.WireVector(bitwidth=128, name='temp_14')
	temp_15 = pyrtl.WireVector(bitwidth=128, name='temp_15')
	temp_16 = pyrtl.WireVector(bitwidth=128, name='temp_16')
	temp_17 = pyrtl.WireVector(bitwidth=128, name='temp_17')
	temp_18 = pyrtl.WireVector(bitwidth=128, name='temp_18')
	temp_19 = pyrtl.WireVector(bitwidth=128, name='temp_19')
	temp_20 = pyrtl.WireVector(bitwidth=128, name='temp_20')
	temp_21 = pyrtl.WireVector(bitwidth=128, name='temp_21')
	temp_22 = pyrtl.WireVector(bitwidth=128, name='temp_22')
github UCSBarchlab / PyRTL / research / aes / aes_decryption.py View on Github external
def addroundkey_1(state, expanded_key):

	input_wire_2 = pyrtl.WireVector(bitwidth=128, name='input_wire_2')
	input_wire_2 <<= state

	new_2 = pyrtl.WireVector(bitwidth=128, name='new_2')
	new_2 <<= state ^ expanded_key[1152:1280]
	return new_2
github UCSBarchlab / PyRTL / research / aes / aes_encryption.py View on Github external
c1_w27 = pyrtl.WireVector(8, 'c1_w27')
	c2_w27 = pyrtl.WireVector(8, 'c2_w27')
	c3_w27 = pyrtl.WireVector(8, 'c3_w27')
	c4_w27 = pyrtl.WireVector(8, 'c4_w27')

	c1_w27 <<= sbox[b1_w27]
	c2_w27 <<= sbox[b2_w27]
	c3_w27 <<= sbox[b3_w27]
	c4_w27 <<= sbox[b4_w27]

	substituted_w27 = pyrtl.WireVector(32, 'substituted_w27')
	substituted_w27 <<= pyrtl.concat(c1_w27, c2_w27, c3_w27, c4_w27)

	# STEP 3: XOR substituted bytes with round constant.
	xor_w27 = pyrtl.WireVector(bitwidth=32, name='xor_w27')
	rc1_w27 = pyrtl.WireVector(bitwidth=8, name='rc1_w27')
	rc2_w27 = pyrtl.WireVector(bitwidth=8, name='rc2_w27')
	rc3_w27 = pyrtl.WireVector(bitwidth=8, name='rc3_w27')
	rc4_w27 = pyrtl.WireVector(bitwidth=8, name='rc4_w27')

	rc1_w27 <<= rcon[7]
	rc2_w27 <<= 0x00
	rc3_w27 <<= 0x00
	rc4_w27<<= 0x00

	concat_w27 = pyrtl.WireVector(32, 'concat_w27')
	concat_w27 <<= pyrtl.concat(rc1_w27, rc2_w27, rc3_w27, rc4_w27)
	xor_w27 <<= concat_w27 ^ substituted_w27
	return xor_w27
github UCSBarchlab / PyRTL / research / aes / aes_decryption.py View on Github external
c2_w7 = pyrtl.WireVector(8, 'c2_w7')
	c3_w7 = pyrtl.WireVector(8, 'c3_w7')
	c4_w7 = pyrtl.WireVector(8, 'c4_w7')

	c1_w7 <<= sbox[b1_w7]
	c2_w7 <<= sbox[b2_w7]
	c3_w7 <<= sbox[b3_w7]
	c4_w7 <<= sbox[b4_w7]

	substituted_w7 = pyrtl.WireVector(32, 'substituted_w7')
	substituted_w7 <<= pyrtl.concat(c1_w7, c2_w7, c3_w7, c4_w7)

	# STEP 3: XOR substituted bytes with round constant.
	xor_w7 = pyrtl.WireVector(bitwidth=32, name='xor_w7')
	rc1_w7 = pyrtl.WireVector(bitwidth=8, name='rc1_w7')
	rc2_w7 = pyrtl.WireVector(bitwidth=8, name='rc2_w7')
	rc3_w7 = pyrtl.WireVector(bitwidth=8, name='rc3_w7')
	rc4_w7 = pyrtl.WireVector(bitwidth=8, name='rc4_w7')

	rc1_w7 <<= rcon[2]
	rc2_w7 <<= 0x00
	rc3_w7 <<= 0x00
	rc4_w7<<= 0x00

	concat_w7 = pyrtl.WireVector(32, 'concat_w7')
	concat_w7 <<= pyrtl.concat(rc1_w7, rc2_w7, rc3_w7, rc4_w7)
	xor_w7 <<= concat_w7 ^ substituted_w7
	return xor_w7
github UCSBarchlab / PyRTL / research / aes / aes_encryption.py View on Github external
a3_w3 = pyrtl.WireVector(8, 'a3_w3')
	a4_w3 = pyrtl.WireVector(8, 'a4_w3')

	a1_w3 <<= word[24:32]
	a2_w3 <<= word[16:24]
	a3_w3 <<= word[8:16]
	a4_w3 <<= word[0:8]

	shifted_w3 = pyrtl.WireVector(32, 'shifted_w3')
	shifted_w3 <<= pyrtl.concat(a2_w3, a3_w3, a4_w3, a1_w3)

	# STEP 2: Substitution of each byte of shifted word.
	b1_w3 = pyrtl.WireVector(8, 'b1_w3')
	b2_w3 = pyrtl.WireVector(8, 'b2_w3')
	b3_w3 = pyrtl.WireVector(8, 'b3_w3')
	b4_w3 = pyrtl.WireVector(8, 'b4_w3')

	b1_w3 <<= shifted_w3[24:32]
	b2_w3 <<= shifted_w3[16:24]
	b3_w3 <<= shifted_w3[8:16]
	b4_w3 <<= shifted_w3[0:8]

	c1_w3 = pyrtl.WireVector(8, 'c1_w3')
	c2_w3 = pyrtl.WireVector(8, 'c2_w3')
	c3_w3 = pyrtl.WireVector(8, 'c3_w3')
	c4_w3 = pyrtl.WireVector(8, 'c4_w3')

	c1_w3 <<= sbox[b1_w3]
	c2_w3 <<= sbox[b2_w3]
	c3_w3 <<= sbox[b3_w3]
	c4_w3 <<= sbox[b4_w3]
github UCSBarchlab / PyRTL / research / aes / aes_encryption.py View on Github external
a12 = in_vector[24:32]
	a13 = in_vector[16:24]
	a14 = in_vector[8:16]
	a15 = in_vector[0:8]

	b0 = pyrtl.WireVector(bitwidth=8)
	b1 = pyrtl.WireVector(bitwidth=8)
	b2 = pyrtl.WireVector(bitwidth=8)
	b3 = pyrtl.WireVector(bitwidth=8)
	b4 = pyrtl.WireVector(bitwidth=8)
	b5 = pyrtl.WireVector(bitwidth=8)
	b6 = pyrtl.WireVector(bitwidth=8)
	b7 = pyrtl.WireVector(bitwidth=8)
	b8 = pyrtl.WireVector(bitwidth=8)
	b9 = pyrtl.WireVector(bitwidth=8)
	b10 = pyrtl.WireVector(bitwidth=8)
	b11 = pyrtl.WireVector(bitwidth=8)
	b12 = pyrtl.WireVector(bitwidth=8)
	b13 = pyrtl.WireVector(bitwidth=8)
	b14 = pyrtl.WireVector(bitwidth=8)
	b15 = pyrtl.WireVector(bitwidth=8)

	b0 <<= galoisMult(a0, 2) ^ galoisMult(a1, 3) ^ a2 ^ a3
	b1 <<= galoisMult(a1, 2) ^ galoisMult(a2, 3) ^ a3 ^ a0
	b2 <<= galoisMult(a2, 2) ^ galoisMult(a3, 3) ^ a0 ^ a1
	b3 <<= galoisMult(a3, 2) ^ galoisMult(a0, 3) ^ a1 ^ a2

	b4 <<= galoisMult(a4, 2) ^ galoisMult(a5, 3) ^ a6 ^ a7
	b5 <<= galoisMult(a5, 2) ^ galoisMult(a6, 3) ^ a7 ^ a4
	b6 <<= galoisMult(a6, 2) ^ galoisMult(a7, 3) ^ a4 ^ a5
	b7 <<= galoisMult(a7, 2) ^ galoisMult(a4, 3) ^ a5 ^ a6
github UCSBarchlab / PyRTL / research / aes / aes_encryption.py View on Github external
temp_22 = pyrtl.WireVector(bitwidth=128, name='temp_22')
	temp_23 = pyrtl.WireVector(bitwidth=128, name='temp_23')
	temp_24 = pyrtl.WireVector(bitwidth=128, name='temp_24')
	temp_25 = pyrtl.WireVector(bitwidth=128, name='temp_25')
	temp_26 = pyrtl.WireVector(bitwidth=128, name='temp_26')
	temp_27 = pyrtl.WireVector(bitwidth=128, name='temp_27')
	temp_28 = pyrtl.WireVector(bitwidth=128, name='temp_28')
	temp_29 = pyrtl.WireVector(bitwidth=128, name='temp_29')
	temp_30 = pyrtl.WireVector(bitwidth=128, name='temp_30')
	temp_31 = pyrtl.WireVector(bitwidth=128, name='temp_31')
	temp_32 = pyrtl.WireVector(bitwidth=128, name='temp_32')
	temp_33 = pyrtl.WireVector(bitwidth=128, name='temp_33')
	temp_34 = pyrtl.WireVector(bitwidth=128, name='temp_34')
	temp_35 = pyrtl.WireVector(bitwidth=128, name='temp_35')
	temp_36 = pyrtl.WireVector(bitwidth=128, name='temp_36')
	temp_37 = pyrtl.WireVector(bitwidth=128, name='temp_37')
	temp_38 = pyrtl.WireVector(bitwidth=128, name='temp_38')
	temp_39 = pyrtl.WireVector(bitwidth=128, name='temp_39')

	# Expanding the key (KeyExpansion).
	expanded_key = pyrtl.WireVector(bitwidth=1408, name='expanded_key')
	expanded_key <<= KeyExpansion(key)

	# Initial AddRoundKey.
	new_state = pyrtl.WireVector(bitwidth=128, name='new_state')
	new_state <<= addroundkey_initial(plaintext, expanded_key)
	
	# # Round 1.
	temp_1 <<= SubBytes(new_state)
	temp_2 <<= ShiftRows(temp_1)
	temp_3 <<= MixColumns(temp_2)
	temp_4 <<= addroundkey_1(temp_3, expanded_key)
github UCSBarchlab / PyRTL / research / aes / aes_encryption.py View on Github external
b1_w3 <<= shifted_w3[24:32]
	b2_w3 <<= shifted_w3[16:24]
	b3_w3 <<= shifted_w3[8:16]
	b4_w3 <<= shifted_w3[0:8]

	c1_w3 = pyrtl.WireVector(8, 'c1_w3')
	c2_w3 = pyrtl.WireVector(8, 'c2_w3')
	c3_w3 = pyrtl.WireVector(8, 'c3_w3')
	c4_w3 = pyrtl.WireVector(8, 'c4_w3')

	c1_w3 <<= sbox[b1_w3]
	c2_w3 <<= sbox[b2_w3]
	c3_w3 <<= sbox[b3_w3]
	c4_w3 <<= sbox[b4_w3]

	substituted_w3 = pyrtl.WireVector(32, 'substituted_w3')
	substituted_w3 <<= pyrtl.concat(c1_w3, c2_w3, c3_w3, c4_w3)

	# STEP 3: XOR substituted bytes with round constant.
	xor_w3 = pyrtl.WireVector(bitwidth=32, name='xor_w3')
	rc1_w3 = pyrtl.WireVector(bitwidth=8, name='rc1_w3')
	rc2_w3 = pyrtl.WireVector(bitwidth=8, name='rc2_w3')
	rc3_w3 = pyrtl.WireVector(bitwidth=8, name='rc3_w3')
	rc4_w3 = pyrtl.WireVector(bitwidth=8, name='rc4_w3')

	rc1_w3 <<= rcon[1]
	rc2_w3 <<= 0x00
	rc3_w3 <<= 0x00
	rc4_w3<<= 0x00

	concat_w3 = pyrtl.WireVector(32, 'concat_w3')
	concat_w3 <<= pyrtl.concat(rc1_w3, rc2_w3, rc3_w3, rc4_w3)
github UCSBarchlab / PyRTL / research / aes / aes_decryption.py View on Github external
c2_w23 = pyrtl.WireVector(8, 'c2_w23')
	c3_w23 = pyrtl.WireVector(8, 'c3_w23')
	c4_w23 = pyrtl.WireVector(8, 'c4_w23')

	c1_w23 <<= sbox[b1_w23]
	c2_w23 <<= sbox[b2_w23]
	c3_w23 <<= sbox[b3_w23]
	c4_w23 <<= sbox[b4_w23]

	substituted_w23 = pyrtl.WireVector(32, 'substituted_w23')
	substituted_w23 <<= pyrtl.concat(c1_w23, c2_w23, c3_w23, c4_w23)

	# STEP 3: XOR substituted bytes with round constant.
	xor_w23 = pyrtl.WireVector(bitwidth=32, name='xor_w23')
	rc1_w23 = pyrtl.WireVector(bitwidth=8, name='rc1_w23')
	rc2_w23 = pyrtl.WireVector(bitwidth=8, name='rc2_w23')
	rc3_w23 = pyrtl.WireVector(bitwidth=8, name='rc3_w23')
	rc4_w23 = pyrtl.WireVector(bitwidth=8, name='rc4_w23')

	rc1_w23 <<= rcon[6]
	rc2_w23 <<= 0x00
	rc3_w23 <<= 0x00
	rc4_w23<<= 0x00

	concat_w23 = pyrtl.WireVector(32, 'concat_w23')
	concat_w23 <<= pyrtl.concat(rc1_w23, rc2_w23, rc3_w23, rc4_w23)
	xor_w23 <<= concat_w23 ^ substituted_w23
	return xor_w23