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

feat(cipher/diffiehellman): add fuzz test to key generators in diffiehellman algorithm #602

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
7. [`EditDistanceRecursive`](./dynamic/editdistance.go#L10): EditDistanceRecursive is a naive implementation with exponential time complexity.
8. [`IsSubsetSum`](./dynamic/subsetsum.go#L14): No description provided.
9. [`Knapsack`](./dynamic/knapsack.go#L17): Knapsack solves knapsack problem return maxProfit
10. [`LongestCommonSubsequence`](./dynamic/longestcommonsubsequence.go#L12): LongestCommonSubsequence function
10. [`LongestCommonSubsequence`](./dynamic/longestcommonsubsequence.go#L13): LongestCommonSubsequence function
11. [`LongestIncreasingSubsequence`](./dynamic/longestincreasingsubsequence.go#L9): LongestIncreasingSubsequence returns the longest increasing subsequence where all elements of the subsequence are sorted in increasing order
12. [`LongestIncreasingSubsequenceGreedy`](./dynamic/longestincreasingsubsequencegreedy.go#L9): LongestIncreasingSubsequenceGreedy is a function to find the longest increasing subsequence in a given array using a greedy approach. The dynamic programming approach is implemented alongside this one. Worst Case Time Complexity: O(nlogn) Auxiliary Space: O(n), where n is the length of the array(slice). Reference: https://www.geeksforgeeks.org/construction-of-longest-monotonically-increasing-subsequence-n-log-n/
13. [`LpsDp`](./dynamic/longestpalindromicsubsequence.go#L25): LpsDp function
Expand Down Expand Up @@ -778,6 +778,19 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
3. [`Queue`](./structure/queue/queuelinkedlist.go#L19): No description provided.


---
</details><details>
<summary> <strong> rot13 </strong> </summary>

---

##### Package rot13 is a simple letter substitution cipher that replaces a letter with the 13th letter after it in the alphabet. ref: https://en.wikipedia.org/wiki/ROT13

---
##### Functions:

1. [`FuzzRot13`](./cipher/rot13/rot13_test.go#L72): No description provided.

---
</details><details>
<summary> <strong> rsa </strong> </summary>
Expand Down
18 changes: 18 additions & 0 deletions cipher/diffiehellman/diffiehellmankeyexchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,21 @@ func TestDiffieHellmanKeyExchange(t *testing.T) {
}
})
}

func FuzzGenSharedKey(f *testing.F) {
f.Add(int64(13))
f.Fuzz(func(t *testing.T, prvKey int64) {
// explicitly ignoring the return value
// here we want to test that no strange behaviors are raised when executing GenerateShareKey
_ = GenerateShareKey(prvKey)
})
}

func FuzzGenMutualKey(f *testing.F) {
f.Add(int64(5), int64(17))
f.Fuzz(func(t *testing.T, prvKey, shrdKey int64) {
// explicitly ignoring the return value
// here we want to test that no strange behaviors are raised when executing GenerateMutualKey
Copy link
Member

Choose a reason for hiding this comment

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

Can you define "strange" behaviour?

I'm of the opinion that these fuzz tests are for checking the unexpected behaviour - that could only be detected once you check the errors (since there are no panics in the algorithm.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

About the reason for these tests: it is mostly to run the function and see if it breaks for unexpected reasons like if there are any issue during the computation done in the algorithm, i.e. divisions by zero, overflows and so on. Let me know what are your thoughts on this.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think there is anything that is being checked for us to conclude that there is nothing "strange" happening. I don't think this is a change with any merit... 😓

_ = GenerateMutualKey(prvKey, shrdKey)
})
}