{"id":15465856,"url":"https://github.com/uhthomas/seekctr","last_synced_at":"2025-06-21T05:05:21.881Z","repository":{"id":57607856,"uuid":"164267980","full_name":"uhthomas/seekctr","owner":"uhthomas","description":"A seekable CTR stream cipher","archived":false,"fork":false,"pushed_at":"2023-12-15T14:44:36.000Z","size":27,"stargazers_count":3,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-19T03:13:04.759Z","etag":null,"topics":["aes","cipher","ctr","go","seek","stream"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uhthomas.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,"zenodo":null}},"created_at":"2019-01-06T02:16:26.000Z","updated_at":"2023-07-25T06:17:48.000Z","dependencies_parsed_at":"2025-04-22T11:20:46.459Z","dependency_job_id":"85efb3c0-e880-4836-9b72-fe44e43fd104","html_url":"https://github.com/uhthomas/seekctr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/uhthomas/seekctr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhthomas%2Fseekctr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhthomas%2Fseekctr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhthomas%2Fseekctr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhthomas%2Fseekctr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uhthomas","download_url":"https://codeload.github.com/uhthomas/seekctr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhthomas%2Fseekctr/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261066462,"owners_count":23104767,"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":["aes","cipher","ctr","go","seek","stream"],"created_at":"2024-10-02T01:03:58.293Z","updated_at":"2025-06-21T05:05:16.864Z","avatar_url":"https://github.com/uhthomas.png","language":"Go","readme":"# seekctr [![GoDoc](https://godoc.org/github.com/uhthomas/seekctr?status.svg)](https://godoc.org/github.com/uhthomas/seekctr)\r\n\r\n[cipher.Stream](https://pkg.go.dev/crypto/cipher#Stream) does not implement [io.Seeker](https://pkg.go.dev/io#Seeker) despite XOR stream ciphers being seekable.\r\n\r\n## Usage\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"io\"\r\n\t\"log\"\r\n\t\"os\"\r\n\r\n\t\"github.com/uhthomas/seekctr\"\r\n)\r\n\r\nfunc main() {\r\n\t// your key and initialization vector\r\n\tvar key, iv []byte\r\n\t// open the encrypted file or stream\r\n\tf, err := os.Open(\"encrypted file\")\r\n\tif err != nil {\r\n\t\tlog.Fatal(err)\r\n\t}\r\n\tr, err := seekctr.NewReader(f, key, iv)\r\n\tif err != nil {\r\n\t\tlog.Fatal(err)\r\n\t}\r\n\t// Seek past the first 1Kb\r\n\tif _, err := r.Seek(1 \u003c\u003c 10); err != nil {\r\n\t\tlog.Fatal(err)\r\n\t}\r\n\t// copy the remaining contents to stdout\r\n\tif _, err := io.Copy(os.Stdout, r); err != nil {\r\n\t\tlog.Fatal(err)\r\n\t}\r\n}\r\n```\r\n\r\n## Note\r\n\r\nRecreating the original stream cipher with a new initialization vector (where `iv += offset / block size`) and discarding the remaining bytes (`offset % block size`) may be preferrable.\r\n\r\n```go\r\nvar key, iv [16]byte\r\n\r\nb, err := aes.NewCipher(key[:])\r\nif err != nil { ... }\r\n\r\noffset := uint64(4 \u003c\u003c 10)\r\n\r\n// offset in chunks\r\nchunks := uint64(int(offset) / b.BlockSize())\r\n\r\n// iv += offset\r\nvar c uint16\r\nfor i := len(iv[:]) - 1; i \u003e= 0; i-- {\r\n\tc = uint16(iv[i]) + uint16(chunks \u0026 0xFF) + c\r\n\tiv[i], c, chunks = byte(c), c \u003e\u003e 8, chunks \u003e\u003e 8\r\n}\r\n\r\n// Reinitialize cipher\r\ns := cipher.NewCTR(b, iv[:])\r\n\r\n// Discard n bytes\r\nd := make([]byte, int(offset) % b.BlockSize())\r\ns.XORKeyStream(d, d)\r\n```\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuhthomas%2Fseekctr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuhthomas%2Fseekctr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuhthomas%2Fseekctr/lists"}