-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Decouple hash algorithms from sign algorithms #12
Comments
There is no desire to support JWT with this package. I actually want to discourage their use wherever possible so it would be counter-productive to have any support for them in core libraries. |
That's great and I agree with the direction. I wanted to add SHA3 to hash function and I don't know how can I proceed with current implementation. It would be great to share the implementation, how can I do it? |
Sorry, I'm getting confused and not understanding the issue. Why wouldn't you implement SHA3 for both hash and hmac? |
I think I wanted to do too many things at once. I will explain my train of thoughts. At first I wanted to add SHA3 to the library. When I tried to do just that, I stumbled on I came to conclusion that it would be beneficial to decouple all the places where HashAlgorithm is used, if breaking changes are needed anyway. It would create three types: This decoupling would allow to do three things:
Alternatively one can just remove |
Sorry, I don't know what you mean about the JWT considerations. There will be no changes made to this library in service of JWT so non-JWT related motivations are required. |
By JWT I mean this part of the code. I call it JWT, because names like HS224, HS256, etc. are related to it. They are defined in RFC-7518 JSON Web Algorithms.
Specifically I have issue with this specific case:
What should you do when you want to add new algorithm, for example: |
Thank you. What is the motivation for adding this new algorithm? |
I wanted to implement CUID2 for Gleam and it uses SHA3 for making id's look random. |
If you implement this in your package then there would be no need to disrupt all the applications and packages that depend on this package. That seems beneficial if there is no other motivation today for splitting the API. |
The other motivation is to make crypto library from Gleam complete. Currently it does not support all algorithms for hashing and signing messages available in Erlang and Node. |
That's not a goal of this package presently. |
Functions
hash
,new_hasher
,hmac
andsign_message
all useHashAlgorithm
to define which algorithm to use.I tried adding new hash algorithms supported by Erlang and Node.js. I stumbled on problem with
sign_message
. It seems that this function implements creation of JSON Web Token (RFC-7519, https://datatracker.ietf.org/doc/html/rfc7519). It uses "alg" field to define which Message Authentication Code algorithm was used to sign the message. I could not find definition for SHA3-X algorithm family in docs (RFC-7518, https://datatracker.ietf.org/doc/html/rfc7518). Additionally, if someone wanted to implement non hash-based message authentication codes (HMAC) it would be impossible to do so with current state. It is because MAC algorithms likeES256 (ECDSA using P-256 and SHA-256)
are not hash based, so algorithm definition for it would make no sense for functions likehash
.My proposal is to move
hash
functions,hmac
functions andsign_message
to separate submodules:hash
,mac
andjwt
respectively. By doing so you will have nice separation of concerns.It will also prevent collisions between algorithm names.
Sha256
can mean something different for thehash
, module, as it refers to a cryptographic hash function, whereas in the mac module, it may represent the hashing algorithm used to generate a Message Authentication Code (MAC).By doing so you could also work on different domains of cryptography without affecting other ones.
My other, less involved proposal is to define separate types for MAC and JWT algorithms. It will also allow to work separately on different types of algorithms. However it will not provide separation of concerns found in Erlang and in Node.
Both my proposals will introduce breaking changes, so I wanted to first discuss them here.
The text was updated successfully, but these errors were encountered: