# Completed: DFINITY Bounty #4: Keccak-256 and SHA3 Motoko Library - $2'000 in ICP

**URL:** <https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469>\
**Category:** Bounties & RFPs\
**Created:** [February 13, 2023, 9:10am UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469 "2023-02-13T09:10:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![domwoe](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/domwoe/32/5165_2.png) [@domwoe](https://forum.dfinity.org/u/domwoe)\
**Post date:** [February 13, 2023, 9:10am UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/1 "2023-02-13T09:10:34Z")

</div>

## Overview

Status: Open  
Project Type: Traditional: One applicant is selected to work on the task.  
Time Commitment: Days  
Experience Level: Intermediate  
Size: USD 2’000 in ICP

## Description

Since the Internet Computer allows canisters to sign Ethereum transactions, there’s a need to hash those transactions. This is currently not directly possible in canisters written in Motoko. and a workaround like calling the [EVM utility canister](https://forum.dfinity.org/t/assigned-icdevs-org-bounty-28-evm-utility-canister-6-000/17880) has to be used.

In this bounty, you will implement two cryptographic hashing algorithms in Motoko. Keccak-256 is the hashing algorithm used for signing Ethereum transactions. It is similar to the standardized SHA-3 but uses a different padding. Hence, it makes sense to include both variations, although the official SHA-3 is not used in Ethereum.

## Acceptance Criteria

- Implementation with tests
- [Meaningful readme](https://github.com/dfinity/grant-rfps/blob/main/repo-checklist.md) with usage example
- Open Source license (e.g. MIT)
- Available in the [mops package manager](https://mops.one/)

## How to apply?

- Include links to previous relevant work.
- Include a brief overview of how you will complete the task.
- Give an estimated timeline for completing the task.
- Post your application text in this thread

## References

### SHA-3 and Keccak implementations

- [GitHub - ethereum/eth-hash: The Ethereum hashing function, keccak256, sometimes (erroneously) called sha256 or sha3](https://github.com/ethereum/eth-hash)
- [hashes/sha3 at master · RustCrypto/hashes · GitHub](https://github.com/RustCrypto/hashes/tree/master/sha3)

### Examples of cryptographic hashing libraries in Motoko

- [GitHub - timohanke/motoko-sha2: Sha2 family in Motoko](https://github.com/timohanke/motoko-sha2)
- [GitHub - aviate-labs/crypto.mo: Crypto Package for Motoko](https://github.com/aviate-labs/crypto.mo)
- [GitHub - tgalal/motoko-bitcoin: Bitcoin library for Motoko](https://github.com/tgalal/motoko-bitcoin)

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [February 13, 2023, 2:39pm UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/2 "2023-02-13T14:39:34Z")

</div>

We’ve been unable to get much traction for this at $4k. [Open: ICDevs.org - Bounty #14 - Big SHA-KECCAK - $4,000 - #15 by timo](https://forum.dfinity.org/t/open-icdevs-org-bounty-14-big-sha-keccak-4-000/11251/15).

I’ve been trying to follow up with gitcoin about their pro account and to see if ICDevs can’t get a discount due to our non-profit status, but I haven’t heard back in a timely manner from them. This would get a lot more transactions over in the ETH realm, so hopefully, the latest contact they’ve given me can get back to me.

---

<div class="post-metadata">

**Author:** ![ginanisque](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ginanisque/32/9442_2.png) [@ginanisque](https://forum.dfinity.org/u/ginanisque)\
**Post date:** [February 17, 2023, 9:29am UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/3 "2023-02-17T09:29:47Z")

</div>

Hello! I am interested in working on this bounty. I can implement the necessary hashing algorithm. I have done something similar for hashing search data. I am unable to include links here. My github profile is ginanisque.  
I will be able complete and delive project in aproximately 10 working days.

---

<div class="post-metadata">

**Author:** ![EricLI123](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ericli123/32/9482_2.png) [@EricLI123](https://forum.dfinity.org/u/EricLI123)\
**Post date:** [February 20, 2023, 1:37am UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/4 "2023-02-20T01:37:25Z")

</div>

Hi I am interested in this project and want to implement those hashing algorithms. Just let me know when I can get started. This should be a straightforward task,

---

<div class="post-metadata">

**Author:** ![domwoe](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/domwoe/32/5165_2.png) [@domwoe](https://forum.dfinity.org/u/domwoe)\
**Post date:** [February 20, 2023, 10:43am UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/5 "2023-02-20T10:43:54Z")

</div>

Hey @EricLI123,

can you share relevant background, prior work, and your Github account?

---

<div class="post-metadata">

**Author:** ![EricLI123](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ericli123/32/9482_2.png) [@EricLI123](https://forum.dfinity.org/u/EricLI123)\
**Post date:** [February 20, 2023, 2:10pm UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/6 "2023-02-20T14:10:53Z")

</div>

@domwoe - thanks for ur reply.  
My github account: WenheLI  
And I have built a couple of hackathon project about web3 development and got some rewards.  
Besides, I am contributors of some well-known open source community like Chromium and TensorFlow.  
Let me know if you want to have more info from me.

---

<div class="post-metadata">

**Author:** ![timk11](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timk11/32/9489_2.png) [@timk11](https://forum.dfinity.org/u/timk11)\
**Post date:** [February 21, 2023, 1:46am UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/7 "2023-02-21T01:46:58Z")

</div>

Hi. I’m interested in working on this bounty. Please see github: timk11 for examples of my work. I’m new to both Motoko and the finer details of hashing algorithms (familiar with the concept) but I plan to put some basic examples of both on my GitHub by the end of the week. I would anticipate completing the task within 30 days of assignment.  
(I’ve also posted this on the Gitcoin bounty site - hope the doubling up is OK)

---

<div class="post-metadata">

**Author:** ![domwoe](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/domwoe/32/5165_2.png) [@domwoe](https://forum.dfinity.org/u/domwoe)\
**Post date:** [February 22, 2023, 6:59am UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/8 "2023-02-22T06:59:15Z")

</div>

Hey everybody,

based on prior experience, as can be evaluated from the public Gihub profile, we decided to assign this bounty to @EricLI123.

Thank you @ginanisque and @timk11 for your interest.

---

<div class="post-metadata">

**Author:** ![timk11](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timk11/32/9489_2.png) [@timk11](https://forum.dfinity.org/u/timk11)\
**Post date:** [February 22, 2023, 10:39am UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/9 "2023-02-22T10:39:09Z")

</div>

Thanks for letting us know, and all the best with the project!

---

<div class="post-metadata">

**Author:** ![domwoe](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/domwoe/32/5165_2.png) [@domwoe](https://forum.dfinity.org/u/domwoe)\
**Post date:** [February 22, 2023, 10:52am UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/10 "2023-02-22T10:52:52Z")

</div>

Btw, I’m not sure you have seen it, but there are more bounties available that haven’t been published on Gitcoin: [Bounties - Internet Computer Developer Forum](https://forum.dfinity.org/c/developers/bounties/37)

---

<div class="post-metadata">

**Author:** ![timk11](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timk11/32/9489_2.png) [@timk11](https://forum.dfinity.org/u/timk11)\
**Post date:** [February 22, 2023, 1:24pm UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/11 "2023-02-22T13:24:49Z")

</div>

Thanks. I’ll have a look through that.

---

<div class="post-metadata">

**Author:** ![ray-react0r](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ray-react0r/32/9567_2.png) [@ray-react0r](https://forum.dfinity.org/u/ray-react0r)\
**Post date:** [February 24, 2023, 8:56pm UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/12 "2023-02-24T20:56:53Z")

</div>

I don’t suppose this bounty is still open? I noticed it got cancelled and reopened on Gitcoin. If it is still open, we’d love to sign up. We started a couple days ago to learn Motoko and related tech to see if we’d like it. We managed to get most of the code written in about 3 days (13 hrs). We’re a team of two with not much open source work to show (working on that with this) but we do have 30+ years in software dev and information security behind us. Happy to post our code sooner rather than later if interested.

Also happy to collaborate with @EricLI123 too as we’re more interested in the exercise than the bounty at this point.

---

<div class="post-metadata">

**Author:** ![ray-react0r](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ray-react0r/32/9567_2.png) [@ray-react0r](https://forum.dfinity.org/u/ray-react0r)\
**Post date:** [February 26, 2023, 9:32pm UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/13 "2023-02-26T21:32:33Z")

</div>

Our code is posted on Github at react0r-com/crypto.mo/blob/main/src/SHA/SHA3.mo if it’s useful to someone. Comments and feedback always welcome.

---

<div class="post-metadata">

**Author:** ![domwoe](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/domwoe/32/5165_2.png) [@domwoe](https://forum.dfinity.org/u/domwoe)\
**Post date:** [March 3, 2023, 12:39pm UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/14 "2023-03-03T12:39:41Z")

</div>

Hey @ray-react0r,

Sorry for the late response. I was on vacation and then on sick leave. The bounty had been assigned and canceled on Gitcoin (and has not been reopened). But both submissions we have now are not from the assigned initial party 🙂

For your contribution, I’m not sure if both, the official SHA3 and Keccak are supported.

Since you forked @quint’s `crypto.mo`, do you plan to provide a Pull Request to this?

---

<div class="post-metadata">

**Author:** ![ray-react0r](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ray-react0r/32/9567_2.png) [@ray-react0r](https://forum.dfinity.org/u/ray-react0r)\
**Post date:** [March 3, 2023, 6:53pm UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/15 "2023-03-03T18:53:28Z")

</div>

No problem at all on the delay. Hah, interesting situation with the bounty then. It’s a fun exercise so I’m not surprised there are more submissions.

Are you referring to the missing bit modes for SHA3? They’re easy enough to add. Given this was already assigned, I didn’t look at the Keccak variant. I’ll take a look if it’ll be more useful that way.

Yea, I was planning on reaching out to see if they’d want a pull request but haven’t got around to it yet.

---

<div class="post-metadata">

**Author:** ![ray-react0r](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ray-react0r/32/9567_2.png) [@ray-react0r](https://forum.dfinity.org/u/ray-react0r)\
**Post date:** [March 3, 2023, 9:08pm UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/16 "2023-03-03T21:08:52Z")

</div>

So I added the missing 224- and 384-bit hash sizes for SHA3 and Keccak-256. Turns out the padding difference is pretty minor. You only need to use the old `0x01` value for Keccak. NIST updated that to `0x06` for SHA3.

The updates along with all the modes are in the react0r-com/crypto.mo/blob/main/src/SHA/ directory of the Github repo.

---

<div class="post-metadata">

**Author:** ![domwoe](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/domwoe/32/5165_2.png) [@domwoe](https://forum.dfinity.org/u/domwoe)\
**Post date:** [March 6, 2023, 8:34am UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/17 "2023-03-06T08:34:48Z")

</div>

Hey @hanbu97,

thank you for your contribution as well!

For everyone else, the contribution is here: [GitHub - hanbu97/motoko-sha3: Keccak/Sha3 implementation in Motoko.](https://github.com/hanbu97/motoko-sha3)

One thing I noticed is that it would be nice to have a more straightforward example in the readme, e.g.

```auto
var sha = SHA3.Keccak(256);
let val = Blob.toArray(Text.encodeUtf8("hello world!"));
sha.update(val);
let result = sha.finalize();

```

instead of using a byte array directly.

---

<div class="post-metadata">

**Author:** ![domwoe](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/domwoe/32/5165_2.png) [@domwoe](https://forum.dfinity.org/u/domwoe)\
**Post date:** [March 6, 2023, 8:36am UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/18 "2023-03-06T08:36:38Z")

</div>

> [@ray-react0r](#):
>
> Yea, I was planning on reaching out to see if they’d want a pull request but haven’t got around to it yet.

That would be great. Otherwise, this was only a nice exercise without much impact.

---

<div class="post-metadata">

**Author:** ![icaten](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icaten/32/9897_2.png) [@icaten](https://forum.dfinity.org/u/icaten)\
**Post date:** [March 6, 2023, 4:25pm UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/19 "2023-03-06T16:25:37Z")

</div>

With this and http outcalls would this make doing PoW mining of blockchains using these encryption schemes possible in a canister?

---

<div class="post-metadata">

**Author:** ![hanbu97](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/hanbu97/32/9657_2.png) [@hanbu97](https://forum.dfinity.org/u/hanbu97)\
**Post date:** [March 7, 2023, 1:42am UTC](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469/20 "2023-03-07T01:42:02Z")

</div>

Great suggestion, I have made the necessary modifications and pushed the updated version. Thank you！

[Next page](https://forum.dfinity.org/t/completed-dfinity-bounty-4-keccak-256-and-sha3-motoko-library-2000-in-icp/18469.md?page=2)
