Skip to content

Commit

Permalink
Initial port from ECE 5745
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidan-McNay committed Dec 28, 2023
0 parents commit bbd608c
Show file tree
Hide file tree
Showing 113 changed files with 13,315 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#=========================================================================
# run_test.yml
#=========================================================================
# Workflow to run PyMTL3 tests

name: Run Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
pytest:
runs-on: ubuntu-latest
strategy:
matrix:
test_cmd:
- ../rsa_xcel_naive ../rsa_xcel_mont

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.7

- name: Install Verilator
run: |
wget https://github.com/cornell-brg/verilator-travisci-cache/raw/master/verilator-travis-4.036.tar.gz
tar -C ${HOME} -xzf verilator-travis-4.036.tar.gz
echo "VERILATOR_ROOT=${HOME}/verilator" >> $GITHUB_ENV
echo "PYMTL_VERILATOR_INCLUDE_DIR=${HOME}/verilator/share/verilator/include" >> $GITHUB_ENV
echo "${HOME}/verilator/bin" >> $GITHUB_PATH
- name: Check Verilator
run: |
echo ${VERILATOR_ROOT}
echo ${PYMTL_VERILATOR_INCLUDE_DIR}
verilator --version
- name: Install dependencies
run: |
sudo apt-get install -y graphviz
pip install --upgrade pip
pip install -U git+https://github.com/cornell-brg/pymtl3@ece4750-2022
pip install rsa
- name: Run tests
timeout-minutes: 5
run: |
mkdir -p hw/build && cd hw/build
pytest ${{ matrix.test_cmd }} --verbose
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#=========================================================================
# Git Ignore Files
#=========================================================================
# We explicitly ignore a default build directory, the autoconf generated
# autom4te.cache directory, and automatically generated python files.
# This makes it easy to do a clean build under the source directory and
# still have it appear clean to git.

.\#*
scripts/work
build*/
autom4te.cache/
__pycache__/
*/.pytest_cache
*.py[cod]
.DS_Store
.cache/
*~
*.*.swp

asic-manual
asic/old

Empty file added algo/montgomery/__init__.py
Empty file.
64 changes: 64 additions & 0 deletions algo/montgomery/decrypt_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#==========================================================
# encrypt_demo.py
#==========================================================
# Demo code for decrypting messages

from rsa_crypt import decrypt

# Get Input

print( "Inputting Private Key..." )
n = int( input( " n? : " ) )
d = int( input( " d? : " ) )

print( "" )
print( "Encrypted Message?" )
print( " - Data values separated by '|', possibly including spaces")
data = input()

# Format data into pieces
data = [ int( datum.strip() ) for datum in data.split( "|" ) ]

# Decrypt the message

message_char_nums = []
message_chars = []

for datum in data:
result = decrypt( datum, d, n )
message_char_nums.append( result )
message_chars.append( chr( result ) )

# Convert data to strings
data = [ str( num ) for num in data ]
message_char_nums = [ str( num ) for num in message_char_nums ]

# Print Data
encrypt_display = "Encrypted Data: "
message_num_display = "Decrypted Data: "
message_display = "Characters: "

for i in range( len( data ) ):
encrypt_num = data[i]
decrypt_num = message_char_nums[i]
message_char = message_chars[i]

max_len = max( len( encrypt_num ), len( decrypt_num ), len( message_char ) )

# Append to display strings

encrypt_display += ( encrypt_num + ( " " * ( max_len - len( encrypt_num ) ) ) )
message_num_display += ( decrypt_num + ( " " * ( max_len - len( decrypt_num ) ) ) )
message_display += ( message_char + ( " " * ( max_len - len( message_char ) ) ) )

if( i != ( len( data ) - 1 ) ): # Not the final element
encrypt_display += " | "
message_num_display += " | "
message_display += " | "

print( "" )
print( encrypt_display )
print( message_num_display )
print( message_display )
print( "" )
print( "Final Decrypted Message: \n{}".format( "".join( message_chars ) ) )
54 changes: 54 additions & 0 deletions algo/montgomery/encrypt_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#==========================================================
# encrypt_demo.py
#==========================================================
# Demo code for encrypting messages

from rsa_crypt import encrypt

# Get Input

print( "Inputting Public Key..." )
n = int( input( " n? : " ) )
e = int( input( " e? : " ) )

message = input( "\nMessage?\n" )
message_chars = [ char for char in message ]
message_char_nums = [ ord( char ) for char in message ]

# Encrypt Data

encrypted_data = []
for i in range( len( message_char_nums ) ):
encrypted_data.append( encrypt( message_char_nums[i], e, n ) )

# Convert data to strings
message_char_nums = [ str( num ) for num in message_char_nums ]
encrypted_data = [ str( num ) for num in encrypted_data ]

# Print Data
message_display = "Message: "
message_num_display = "Values: "
encrypted_display = "Encrypted: "

for i in range( len( message_chars ) ):
char = message_chars[i]
num = message_char_nums[i]
encrypt_num = encrypted_data[i]

max_len = max( len( char ), len( num ), len( encrypt_num ) )

# Append to display strings

message_display += ( char + ( " " * ( max_len - len( char ) ) ) )
message_num_display += ( num + ( " " * ( max_len - len( num ) ) ) )
encrypted_display += ( encrypt_num + ( " " * ( max_len - len( encrypt_num ) ) ) )

if( i != ( len( message_chars ) - 1 ) ): # Not the final element
message_display += " | "
message_num_display += " | "
encrypted_display += " | "

print( "" )
print( message_display )
print( message_num_display )
print( encrypted_display )
20 changes: 20 additions & 0 deletions algo/montgomery/gen_keys_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#==========================================================
# gen_keys_demo.py
#==========================================================
# Demo code for generating RSA keys

from rsa_genkeys import gen_keys

# Get the keys to use
keys = gen_keys()
n = keys['public key']['n']
e = keys['public key']['e']
d = keys['private key']['d']

print( "Public-Private key pair:")
print( " - Public Key:" )
print( " - n: {}".format( n ) )
print( " - e: {}".format( e ) )
print( " - Private Key:" )
print( " - n: {}".format( n ) )
print( " - d: {}".format( d ) )
Loading

0 comments on commit bbd608c

Please sign in to comment.