{"id":16696657,"url":"https://github.com/zenithalhourlyrate/rvv-mmm","last_synced_at":"2025-03-14T03:11:29.163Z","repository":{"id":68571444,"uuid":"499256902","full_name":"ZenithalHourlyRate/rvv-mmm","owner":"ZenithalHourlyRate","description":null,"archived":false,"fork":false,"pushed_at":"2022-06-06T06:59:29.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-01-20T22:13:05.953Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZenithalHourlyRate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-02T19:02:43.000Z","updated_at":"2022-06-06T05:52:02.000Z","dependencies_parsed_at":"2023-03-01T22:01:13.097Z","dependency_job_id":null,"html_url":"https://github.com/ZenithalHourlyRate/rvv-mmm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZenithalHourlyRate%2Frvv-mmm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZenithalHourlyRate%2Frvv-mmm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZenithalHourlyRate%2Frvv-mmm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZenithalHourlyRate%2Frvv-mmm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZenithalHourlyRate","download_url":"https://codeload.github.com/ZenithalHourlyRate/rvv-mmm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243515567,"owners_count":20303258,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T17:44:29.489Z","updated_at":"2025-03-14T03:11:29.132Z","avatar_url":"https://github.com/ZenithalHourlyRate.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rvv-mmm\n\nMontgomery Modular Multiplication (MMM) in RISC-V Vector Extension (RVV).\n\nMMM is extensively used in RSA/ECC/PQC/ZKP.\n\nThis is based on [Montgomery Multiplication on the Cell](https://link.springer.com/chapter/10.1007/978-3-642-14390-8_50). We have a reference implementation of the algorithm in `mmm.py`\n\nThe efficiency of this implementation is expected to be very bad, use at your own risk! Current implementation can only be used as baseline. I will implement algorithms from existing papers one by one.\n\nYou can see all the parameters in `mmm.pl`. We use perlasm here for more parameterized code generation (e.g. for different VLEN and BN) instead of intrinsics. More documentation on this will be added.\n\n`mmm.pl` (do not use as there is a bug) is fully unrolled, and we dont need extra memory access in this implementation. The only memory access is the first two loads and last one store. But the code size is a concern. when we set VLEN=2048 and BN=4096 for RSA4096, the code size is 65KiB. You can learn the detail of the algorithm from this file and `mmm.py`. Versions below is quite complex and they are based on `mmm.pl`.\n\n`mmm_loop.pl` is a version with loops thus it reduces code size, but then there is overhead on moving data between vregs (`vmv.v.v`).\n\n`mmm_mem.pl` is a version capable of bigger BN with limited VLEN (e.g. RSA4096 with VLEN=128). During computation it saves/restores BN to/from the variable, The efficiency could be problem if the cache is not big enough, but the code size is pretty good now.\n\n## demo\n\nOne demo of this repo is in \u003chttps://github.com/openssl/openssl/pull/18479\u003e\n\n## usage\n\nTo run the RVV program, you can try\n\n```bash\nperl mmm_loop.pl \u003e mmm.S\n# clang 14 is suggested\nclang --target=riscv64 -march=rv64gcv -static -o mmm mmm.S mmm_main.c\nspike --isa=rv64gcv --varch=vlen:128,elen:32 pk mmm\n# or you can use make run for all these above\n```\n\nWe have a reference implementation of the above paper in Python, just try the following command and you will find the answer as above\n\n```bash\npython mmm.py\n# or make ref\n```\n\n## 4096\n\nThe biggest ever MMM is for RSA4096. A demo for 4096-bit mmm is given by `mmm_mem.pl`\n\n```bash\nperl mmm_mem.pl \u003e mmm4096.S\n# clang 14 is suggested\nclang --target=riscv64 -march=rv64gcv -static -o mmm4096 mmm4096.S mmm_main4096.c\nspike --isa=rv64gcv --varch=vlen:128,elen:32 pk mmm4096\n# or make run4096\n```\n\nAnd the reference for it\n```bash\npython mmm4096.py\n# or make ref4096\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzenithalhourlyrate%2Frvv-mmm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzenithalhourlyrate%2Frvv-mmm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzenithalhourlyrate%2Frvv-mmm/lists"}