campeon23 / split-fetcher

The code is a concurrent file downloader in Go that splits a file into multiple parts, downloads them in parallel, and assembles the final file, with support for Etag validation to ensure file integrity.
MIT License
1 stars 0 forks source link

Enhancement of Randomness in generateRandomSalt Method #148

Closed campeon23 closed 1 year ago

campeon23 commented 1 year ago

Description: The current implementation of generateRandomSalt utilizes the rand.Int method for random salt generation. Although functional, there's an alternative which is simpler and more widely accepted in cryptographic contexts.

Recommendation: Adopt io.ReadFull(rand.Reader, results) for enhanced randomness and alignment with best practices in cryptographic applications.

Example Fix:

import (
    "crypto/rand"
    "io"
)

func generateRandomSalt(length int) ([]byte, error) {
    salt := make([]byte, length)
    _, err := io.ReadFull(rand.Reader, salt)
    if err != nil {
        return nil, err
    }
    return salt, nil
}

Acceptance Criteria:

  • Replace rand.Int method with io.ReadFull(rand.Reader, results).
  • Validate the effectiveness of the new randomness generation via tests.
  • Document the rationale for the change and the steps taken.

Severity Level: Medium

campeon23 commented 1 year ago

This ticket has been successfully resolved. We transitioned from the rand.Int method to the io.ReadFull(rand.Reader, results) approach for our salt generation, offering a significant enhancement in line with cryptographic standards. This refactoring not only streamlines the process but ensures that we're generating salts with the highest degree of randomness possible. To substantiate this change, rigorous tests were performed, all of which confirmed the robustness of our new method. For a deeper understanding, we've updated our documentation which now provides both the rationale for this shift and a step-by-step overview of the modifications. We believe this change solidifies the security posture of our application. Thank you for bringing attention to this aspect.