This commit introduces the foundational structure for Montgomery multiplication in `field.go`, including methods for converting to and from Montgomery form, as well as a multiplication function. The current implementation uses standard multiplication internally, with a placeholder for future optimizations. Additionally, a new markdown file, `MONTGOMERY_NOTES.md`, outlines the current status, issues, and next steps for completing the Montgomery multiplication implementation.
1.2 KiB
1.2 KiB
Montgomery Multiplication Implementation Notes
Status
Montgomery multiplication has been partially implemented in field.go. The current implementation provides the API structure but uses standard multiplication internally.
Current Implementation
ToMontgomery(): Converts to Montgomery form using R² multiplicationFromMontgomery(): Converts from Montgomery form (currently uses standard multiplication)MontgomeryMul(): Multiplies two Montgomery-form elements (currently uses standard multiplication)montgomeryReduce(): REDC algorithm implementation (partially complete)
Issues
- The
FromMontgomery()implementation needs proper R⁻¹ computation - The
MontgomeryMul()should use the REDC algorithm directly instead of standard multiplication - The R² constant may need verification
- Tests are currently failing due to incomplete implementation
Next Steps
- Compute R⁻¹ mod p correctly
- Implement proper REDC algorithm in MontgomeryMul
- Verify R² constant against reference implementation
- Add comprehensive tests
References
- Montgomery reduction: https://en.wikipedia.org/wiki/Montgomery_modular_multiplication
- secp256k1 field implementation: src/field_5x52.h