{"action":"opened","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/23629","repository_url":"https://api.github.com/repos/dotnet/corefx","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/23629/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/23629/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/23629/events","html_url":"https://github.com/dotnet/corefx/issues/23629","id":253510044,"number":23629,"title":"General low level primitive for ciphers (AES-GCM being the first)","user":{"login":"Drawaes","id":16406969,"avatar_url":"https://avatars2.githubusercontent.com/u/16406969?v=4","gravatar_id":"","url":"https://api.github.com/users/Drawaes","html_url":"https://github.com/Drawaes","followers_url":"https://api.github.com/users/Drawaes/followers","following_url":"https://api.github.com/users/Drawaes/following{/other_user}","gists_url":"https://api.github.com/users/Drawaes/gists{/gist_id}","starred_url":"https://api.github.com/users/Drawaes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Drawaes/subscriptions","organizations_url":"https://api.github.com/users/Drawaes/orgs","repos_url":"https://api.github.com/users/Drawaes/repos","events_url":"https://api.github.com/users/Drawaes/events{/privacy}","received_events_url":"https://api.github.com/users/Drawaes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-08-29T02:23:26Z","updated_at":"2017-08-29T02:23:26Z","closed_at":null,"body":"# Rationale \r\n\r\nThere is a general need for a number of ciphers for encryption.  Todays mix of interfaces and classes has become a little disjointed. Also there is no support for AEAD style ciphers as they need the ability to provide extra authentication information. The current designs are also prone to allocation and these are hard to avoid due to the returning arrays.\r\n\r\n# Proposed API\r\n\r\nA general purpose abstract base class that will be implemented by concrete classes. This will allow for expansion and also by having a class rather than static methods we have the ability to make extension methods as well as hold state between calls. The API should allow for recycling of the class to allow for lower allocations (not needing a new instance each time, and to catch say unmanaged keys). Due to the often unmanaged nature of resources that are tracked the class should implement IDisposable\r\n\r\n``` csharp\r\npublic abstract class Cipher : IDisposable\r\n{\r\n    public virtual int TagSize { get; }\r\n    public virtual int NonceSize { get; }\r\n    public virtual int BlockSize { get; }\r\n    public virtual bool SupportsAssociatedData { get; }\r\n    public virtual void Init(Span<byte> key, Span<byte> nonce) => throw new NotImplementedException();\r\n    public virtual Reset(Span<byte> nonce) => throw new NotImplementedException();\r\n    public virtual Update(Span<byte> input, Span<byte> output) => throw new NotImplementedException();\r\n    public virtual int Update(Span<byte> inputAndOutput) => Update(inputAndOutput, inputAndOutput);\r\n    public virtual int Finish(Span<byte> inputAndOutput) => Finish(inputAndOutput, inputAndOutput);\r\n    public virtual int Finish(Span<byte> input, Span<byte> output) => throw new NotImplementedException();\r\n    public virtual void AddAssociatedData(Span<byte> AddAssociatedData) => throw new NotImplementedException();\r\n    public virtual void GetTag(Span<byte> span) => throw new NotImplementedException();\r\n    public virtual void SetTag(ReadOnlySpan<byte> tagSpan) => throw new NotImplementedException();\r\n}\r\n```\r\n\r\n# Example Usage\r\n(the input/output source is a mythical span based stream like IO source)\r\n\r\n``` csharp\r\nusing (var cipher = new AesGcmCipher(bitsize: 256))\r\n{\r\n    cipher.Init(myKey, nonce);\r\n    while (!inputSource.EOF)\r\n    {\r\n        var inputSpan = inputSource.ReadSpan(cipher.BlockSize);\r\n        cipher.Update(inputSpan);\r\n        outputSource.Write(inputSpan);\r\n    }\r\n    cipher.AddAssociatedData(extraInformation);\r\n    cipher.Finish(finalBlockData);\r\n    cipher.GetTag(tagData);\r\n}\r\n```\r\n\r\nReference #7023 \r\n"}}
{"actor":{"display_login":"Drawaes"}}