联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2020-09-20 10:13

SEED Labs 1

Crypto Lab – Secret-Key Encryption

Copyright ?c 2006 - 2014 Wenliang Du, Syracuse University.

The development of this document is/was funded by three grants from the US National Science Foundation:

Awards No. 0231122 and 0618680 from TUES/CCLI and Award No. 1017771 from Trustworthy Computing.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free

Documentation License, Version 1.2 or any later version published by the Free Software Foundation. A copy

of the license can be found at http://www.gnu.org/licenses/fdl.html.

1 Overview

The learning objective of this lab is for students to get familiar with the concepts in the secret-key encryption.

After finishing the lab, students should be able to gain a first-hand experience on encryption algorithms .

Moreover, students will be able to use tools and write programs to encrypt/decrypt messages.

2 Lab Environment

Installing OpenSSL. In this lab, we will use openssl commands and libraries. We have already installed

openssl binaries in our VM. It should be noted that if you want to use openssl libraries in

your programs, you need to install several other things for the programming environment, including the

header files, libraries, manuals, etc. We have already downloaded the necessary files under the directory

/home/seed/openssl-1.0.1. To configure and install openssl libraries, go to the openssl-1.0.1

folder and run the following commands.

You should read the INSTALL file first:

% sudo ./config

% sudo make

% sudo make test

% sudo make install

Installing a hex editor. In this lab, we need to be able to view and modify files of binary format. We have

installed in our VM a hex editor called GHex. It allows the user to load data from any file, view and edit it

in either hex or ascii. Note: many people told us that another hex editor, called Bless, is better; this tool

may not be installed in the VM version that you are using, but you can install it yourself using the following

command:

% sudo apt-get install bless

3 Lab Tasks

3.1 Task 1: Encryption using different ciphers

In this task, we will play with various encryption algorithms and modes. You can use the following

openssl enc command to encrypt/decrypt a file. To see the manuals, you can type man openssl

and man enc.

SEED Labs 2

% openssl enc ciphertype -e -in plain.txt -out cipher.bin \

-K 00112233445566778889aabbccddeeff \

-iv 0102030405060708

Please replace the ciphertype with a specific cipher type, such as -aes-128-cbc, -bf-cbc, etc.

In this task, you should try at least 3 different ciphers . You can find the meaning of the command-line

options and all the supported cipher types by typing "man enc". We include some common options for

the openssl enc command in the following:

-in <file> input file

-out <file> output file

-e encrypt

-d decrypt

-K/-iv key/iv in hex is the next argument

-[pP] print the iv/key (then exit if -P)

3.2 Task 2: Programming using the Crypto Library

So far, we have learned how to use the tools provided by openssl to encrypt and decrypt messages. In

this task, we will learn how to use openssl’s crypto library to encrypt/descrypt messages in programs.

OpenSSL provides an API called EVP, which is a high-level interface to cryptographic functions. Although

OpenSSL also has direct interfaces for each individual encryption algorithm, the EVP library provides

a common interface for various encryption algorithms. To ask EVP to use a specific algorithm, we simply

need to pass our choice to the EVP interface. A sample code is given in https://www.openssl.

org/docs/man1.0.2/crypto/EVP_EncryptInit.html. Please get yourself familiar with this

program, and then do the following exercise.

You are given a plaintext and a ciphertext, and you know that aes-128-cbc is used to generate the

ciphertext from the plaintext, and you also know that the numbers in the IV are all zeros (not the ASCII

character ‘0’). Another clue that you have learned is that the key used to encrypt this plaintext is an English

word shorter than 16 characters; the word that can be found from a typical English dictionary. Since the

word has less than 16 characters (i.e. 128 bits), space characters (hexadecimal value 0x20) are appended to

the end of the word to form a key of 128 bits. Your goal is to write a program to find out this key. You can

download a English word list from the Internet. We have also linked one on the web page of this lab. The

plaintext and ciphertext is in the following:

Plaintext (total 21 characters): This is a top secret.

Ciphertext (in hex format): 8d20e5056a8d24d0462ce74e4904c1b5

13e10d1df4a2ef2ad4540fae1ca0aaf9

Note 1: If you choose to store the plaintex message in a file, and feed the file to your program, you need

to check whether the file length is 21. Some editors may add a special character to the end of the file. If that

happens, you can use a hex editor tool to remove the special character.

Note 2: In this task, you are supposed to write your own program to invoke the crypto library. No credit

will be given if you simply use the openssl commands to do this task.

SEED Labs 3

Note 3: To compile your code, you may need to include the header files in openssl, and link to

openssl libraries. To do that, you need to tell your compiler where those files are. In your Makefile,

you may want to specify the following:

INC=/usr/local/ssl/include/

LIB=/usr/local/ssl/lib/

all:

gcc -I$(INC) -L$(LIB) -o enc yourcode.c -lcrypto -ldl

4 Submission

You need to submit a detailed lab report to describe what you have done and what you have observed; you

also need to provide explanation to the observations that are interesting or surprising. In your report, you

need to answer all the questions listed in this lab.


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp