-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Es netssl #1
Changes from 14 commits
f895ee2
8a6f308
4fad1e6
ad3a902
7e112ac
85d8231
774e3c2
99dd2b8
1e3ce4d
7ede1e2
6cc35d7
87b3e27
00ac619
e827e9b
128b255
a3dc4c2
8c45fde
397c18c
93c16ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Result := key_sizes.has (key_size) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I will export it to |
||
-- 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bad indentation, and missing space before There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.