PTT Test

Task

Develop an utility in C (C11 standard) that allows the user to encrypt and decrypt the entered login and password using the AES algorithm. The key length is specified by the user, and the key is generated automatically. The program should consist of 3 separate modules:

  1. Main module
  2. Module containing functions for working with passwords and notifying the user about the correctness of the entered data
  3. Module containing encryption functions

Note:

  • Implement the encryption algorithm using third-party libraries known to you (any mode and algorithm settings).
  • Optionally, implement input validation, as well as ensuring that after encryption and subsequent decryption, the user’s login and password remain correct. This will be an additional plus.

Dependencies

The project uses OpenSSL libssl. The development was done under Visual Studio Code.

    sudo apt install build-essential libssl-dev

Build

Configuration is being selected within a Makefile and is defined by VERSION Variable. Options are 'Release' or 'Debug'.

    git clone ...
    cd ptt-test
    make all

Binary path: ./bin/$(VERSION)/ptt-test

Usage

Usage: ./bin/Debug/ptt-test -l login -p password -k key_length (default: 256 bit)

desktop:~/proj/ptt-test$ ./bin/Debug/ptt-test -l jkjhkjhljlksajdhflkjhasdfpiuewmqicoerimopqueiwucmpoq -p "q43weqweQWE12iuyiuyqiuwye*798(J" -k 256

Key length: 256 bit
Login: 'jkjhkjhljlksajdhflkjhasdfpiuewmqicoerimopqueiwucmpoq'
Password: 'q43weqweQWE12iuyiuyqiuwye*798(J'
Allocations done

Generated key
 99 94 1C 1C A5 48 A7 D4 DA D1 70 4C 38 23 92 DE
 6B 11 B6 D4 20 CF 56 EC 32 07 99 4F 75 4B 50 9D
Encrypted Login         64 bytes @ 0xaaaaf73486b0:
  dump:
 C7 9B 38 68 38 B1 FF A5 BB 43 DF DD B2 AA 4F 04
 08 0F 5D 99 D0 B6 75 37 77 CB 9D B0 AB 3B 7E 92
 DA 6B E7 7F 04 F7 88 52 55 93 C1 DB 43 52 1C FE
 9F 73 1B 43 73 2D EB E6 15 04 CC 17 75 52 B7 64
Encrypted Password      32 bytes @ 0xaaaaf7348930:
  dump:
 5B F0 9E 83 63 FE 87 57 3A EB 58 09 00 11 BB AB
 34 CB 2A 92 C6 75 83 03 FB 2E 03 9E A5 0C F0 BC
Encryption done

Decrypted Login         52 bytes @ 0xaaaaf73487f0: 'jkjhkjhljlksajdhflkjhasdfpiuewmqicoerimopqueiwucmpoq'
  dump:
 6A 6B 6A 68 6B 6A 68 6C 6A 6C 6B 73 61 6A 64 68
 66 6C 6B 6A 68 61 73 64 66 70 69 75 65 77 6D 71
 69 63 6F 65 72 69 6D 6F 70 71 75 65 69 77 75 63
 6D 70 6F 71
Decrypted Password      31 bytes @ 0xaaaaf7348a70: 'q43weqweQWE12iuyiuyqiuwye*798(J'
  dump:
 71 34 33 77 65 71 77 65 51 57 45 31 32 69 75 79
 69 75 79 71 69 75 77 79 65 2A 37 39 38 28 4A
Decryption done

Login:
  [Same] jkjhkjhljlksajdhflkjhasdfpiuewmqicoerimopqueiwucmpoq -> jkjhkjhljlksajdhflkjhasdfpiuewmqicoerimopqueiwucmpoq
Password:
  [Same] q43weqweQWE12iuyiuyqiuwye*798(J -> q43weqweQWE12iuyiuyqiuwye*798(J

VS Code project configuration

Project configuration according to https://earthly.dev/blog/vscode-make/ or similar. It is useful to install the MemoryView, Makefile Tools, C/C++ Extensions.