Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Es netssl #1

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f895ee2
Initial import EVP GCM mode.
jvelilla Jan 10, 2018
8a6f308
Updated SSL_EVP interface : added encryption features.
jvelilla Jan 11, 2018
4fad1e6
Updated Decrypt example using byte array converter.
jvelilla Jan 11, 2018
ad3a902
Initial SSL_GCM high level API.
jvelilla Jan 12, 2018
7e112ac
Made BYTE_ARRAY_CONVERTER as hidden (implementation) class.
jocelyn Jan 16, 2018
85d8231
Merge pull request #1 from jocelyn/es_openssl_crypto
jvelilla Jan 16, 2018
774e3c2
Updated OpenSSL crypto cluster, added a new cluster `wrapper' to have…
jvelilla Jan 17, 2018
99dd2b8
Update OpenSSL libcrypto interface.
jvelilla Jan 19, 2018
1e3ce4d
Updated SSL crypt algorithms.
jvelilla Jan 25, 2018
7ede1e2
Updated OpenSSL crypto targeting Symmetric encryption (ie AES with GCM).
jvelilla Jan 30, 2018
6cc35d7
Renamed cluster experimental as to_remove.
jvelilla Jan 31, 2018
87b3e27
Updated SSL_CIPHER_CONTEXT_EXTERNAL implementation with the
jvelilla Jan 31, 2018
00ac619
Merge branch 'master' of https://github.com/EiffelSoftware/EiffelStud…
jvelilla Feb 6, 2018
e827e9b
Updated OpenSSL library
jvelilla Feb 13, 2018
128b255
Updated copyright.
jvelilla Mar 1, 2018
a3dc4c2
Updated directory structure to describe symetric and asymetric encryp…
jvelilla Mar 2, 2018
8c45fde
Merge branch 'master' of https://github.com/EiffelSoftware/EiffelStud…
jvelilla Mar 8, 2018
397c18c
Merge branch 'master' of https://github.com/EiffelSoftware/EiffelStud…
jvelilla Mar 12, 2018
93c16ab
Updated OpenSSL library to latest release 1.1.0g
jvelilla Mar 13, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Src/unstable/library/network/openssl/openssl.ecf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-17-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-17-0 http://www.eiffel.com/developers/xml/configuration-1-17-0.xsd" name="openssl" uuid="22EE78DC-1AC1-4EBC-8AA9-9E8D6B8C3989" library_target="openssl">
<target name="openssl">
<description>Eiffel OpenSSL Wrap library.
<description>Eiffel OpenSSL Wrap library.
Copyright (c) 1984-2006, Eiffel Software and others.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright year should be updated

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt).</description>
<root all_classes="true"/>
Expand All @@ -26,7 +26,6 @@
<platform value="windows"/>
</condition>
</external_object>

<external_object location="$(ISE_LIBRARY)\unstable\library\network\openssl\spec\$(ISE_PLATFORM)\lib\$(ISE_C_COMPILER)\libcryptoMT.lib">
<condition>
<platform value="windows"/>
Expand Down Expand Up @@ -70,5 +69,15 @@
</condition>
</cluster>
</cluster>
<cluster name="support" location="support\" recursive="true" hidden="true"/>
</target>
<target name="openssl_tests" extends="openssl">
<root class="APPLICATION" feature="make"/>
<option warning="true">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<setting name="console_application" value="true"/>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
<cluster name="test" location=".\test\" recursive="true"/>
</target>
</system>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
note
description: "[
AES (Advanced Encryption Standard) is a block cipher standardized by NIST. AES is both fast, and cryptographically strong. It is a good default choice for encryption.
]"
date: "$Date$"
revision: "$Revision$"

class
SSL_AES

inherit

SSL_ALGORITHM

SSL_CIPHER_ALGORITHM

SSL_BLOCK_CIPHER_ALGORITHM

create
make

feature {NONE} -- Initialization

make (a_key: READABLE_STRING_8)
do
key := a_key
ensure
key_set: key = a_key
valid_key: verify_key_size
end

feature -- Access

name: STRING_8 = "AES"
-- <Precursor>

block_size: INTEGER = 128
-- <Precursor>

key_sizes: ARRAY [INTEGER]
-- <Precursor>
do
Result := {ARRAY[INTEGER]}<<128,192,256,512>>
end

key_bytes: MANAGED_POINTER
-- <Precursor>
do
create Result.make_from_array((create {BYTE_ARRAY_CONVERTER}.make_from_hex_string (key)).to_natural_8_array)
end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
note
description: "[
Object representing cryptographic algorithms supported by OpenSSL like
AES, Blowfish, Camellia, SEED, CAST-128, DES, IDEA, RC2, RC4, RC5, Triple DES, GOST 28147-89
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=OpenSSL algorithms", "src=https://en.wikipedia.org/wiki/OpenSSL#Algorithms", "protocol=uri"

deferred class
SSL_ALGORITHM


feature -- Access

key: STRING_8
-- String representation.

key_bytes: MANAGED_POINTER
-- key represented as bytes.
deferred
end

key_sizes: ARRAY [INTEGER]
-- valid key sizes.
deferred
end

key_size: INTEGER
-- key size of the current algorithm.
do
Result := key_bytes.count * 8
end

feature -- Status Report

verify_key_size: BOOLEAN
-- has the current algorithm a valid key size?
do
if key_sizes.has (key_size) then
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Result := key_sizes.has (key_size)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Result := True
end
end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
note
description: "{
Represent a block cipher algorithm.
}"
date: "$Date$"
revision: "$Revision$"

deferred class
SSL_BLOCK_CIPHER_ALGORITHM

feature -- Access

block_size: INTEGER
-- The size of a block as an integer in bits (e.g. 64, 128).
deferred
end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
note
description: "{
Represent a Cipher Algorithm
}"
date: "$Date$"
revision: "$Revision$"

deferred class
SSL_CIPHER_ALGORITHM

feature -- Access

name: STRING
-- name of the algorithm.
deferred
end

key_size: INTEGER
-- The size of the key being used as an integer in bits (e.g. 128, 256).
deferred
end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
note
description: "Summary description for {SSL_AEAD_CIPHER_CONTEXT_IMPL}."
date: "$Date$"
revision: "$Revision$"

class
SSL_AEAD_CIPHER_CONTEXT_IMPL

inherit

SSL_CIPHER_CONTEXT
SSL_AEAD_CIPHER_CONTEXT
SSL_AEAD_DECRYPTION_CONTEXT
SSL_SHARED_EXCEPTIONS

create
make

feature {NONE} -- Initialization

make (a_ctx: SSL_CIPHER_CONTEXT_EXTERNALS)
do
ctx := a_ctx
bytes_processed := 0
aad_bytes_processed := 0
updated := False
ensure
ctx_setted: ctx = a_ctx
updated_setted: updated = False
end

feature -- Access

ctx: SSL_CIPHER_CONTEXT_EXTERNALS
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should ctx be protected (export NONE) and renamed implementation or externals ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I will export it to {NONE}, but I like the name ctx or context since it's more natural in this domain.

-- cipher context.

bytes_processed: INTEGER
-- number of bytes processed.

aad_bytes_processed: INTEGER
-- number of aad bytes processed.

tag: detachable MANAGED_POINTER

updated: BOOLEAN

feature -- Status Report

check_limit (a_data_size: INTEGER)
local
l_description: STRING
do
-- TODO review this.
if ctx.finalized then
raise_exception ("Context was already finalized.")
else
updated := True
bytes_processed := bytes_processed + a_data_size
-- if bytes_processed > ctx.mode.MAX_ENCRYPTED_BYTES then
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either add a comment related to the commented lines, or remove those lines

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

-- create l_description.make_from_string (ctx.mode.name)
-- l_description.append_string (" has a maximum encrypted byte limit of ")
-- l_description.append_string (ctx.mode.MAX_ENCRYPTED_BYTES)
-- raise_exception (l_description)
-- end
end
end

feature -- Update

update (a_data: MANAGED_POINTER): MANAGED_POINTER
-- <Precursor>
do
check_limit (a_data.count)
Result := ctx.update (a_data)
end

update_into(a_data, a_buf: MANAGED_POINTER): INTEGER
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad indentation, and missing space before (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

-- <Precursor>
do
check_limit (a_data.count)
Result := ctx.update_into (a_data, a_buf)
end

feature -- Finalize

finalize: MANAGED_POINTER
-- <Precursor>
do
create Result.make (0)
if ctx.finalized then
raise_exception ("Context was already finalized.")
else
Result := ctx.finalize
tag := ctx.tag
ctx.clean_context
end
end

finalize_with_tag (a_tag: MANAGED_POINTER): MANAGED_POINTER
-- <Precursor>
do
create Result.make (0)
if ctx.finalized then
raise_exception ("Context was already finalized.")
else
Result := ctx.finalize_with_tag (a_tag)
tag := ctx.tag
ctx.clean_context
end
end

authenticate_additional_data (a_data: MANAGED_POINTER)
-- <Precursor>
local
l_description: STRING
do
if ctx.finalized then
raise_exception ("Context was already finalized.")
end
if updated then
raise_exception ("Update has been called on this context.")
end

aad_bytes_processed := aad_bytes_processed + a_data.count
-- if aad_bytes_processed > ctx.mode.MAX_AAD_BYTES then
-- create l_description.make_from_string (ctx.mode.name)
-- l_description.append_string (" has a maximum AAD byte limit of ")
-- l_description.append_string (ctx.mode.MAX_AAD_BYTES)
-- raise_exception (l_description)
-- end
ctx.authenticate_additional_data (a_data)
end

end


Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
note
description: "Summary description for {SSL_AEAD_ENCRYPTION_CONTEXT_IMPL}."
author: ""
date: "$Date$"
revision: "$Revision$"

class
SSL_AEAD_ENCRYPTION_CONTEXT_IMPL

inherit

SSL_AEAD_CIPHER_CONTEXT_IMPL
rename
tag as tag_value
end

SSL_AEAD_ENCRYPTION_CONTEXT

create
make

feature -- ACCESS


tag: detachable MANAGED_POINTER
-- <Precursor>
do
if not ctx.finalized then
raise_exception ("You must finalize encryption before getting the tag")
end
Result := tag_value
end

end
Loading