{"action":"created","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":[{"id":163633782,"url":"https://api.github.com/repos/dotnet/corefx/labels/area-System.Security","name":"area-System.Security","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":29,"created_at":"2017-08-29T02:23:26Z","updated_at":"2017-09-06T23:51:58Z","closed_at":null,"author_association":"COLLABORATOR","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 IVSize { get; }\r\n    public virtual int BlockSize { get; }\r\n    public virtual bool SupportsAssociatedData { get; }\r\n\r\n    public abstract void Init(ReadOnlySpan<byte> key, ReadOnlySpan<byte> iv);\r\n    public abstract void Init(ReadOnlySpan<byte> iv);\r\n    public abstract int Update(ReadOnlySpan<byte> input, Span<byte> output);\r\n    public abstract int Finish(ReadOnlySpan<byte> input, Span<byte> output);\r\n    public abstract void AddAssociatedData(ReadOnlySpan<byte> associatedData);\r\n    public abstract int GetTag(Span<byte> span);\r\n    public abstract void SetTag(ReadOnlySpan<byte> tagSpan);\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\n# API Behaviour\r\n\r\n1. If get tag is called before finish a [exception type?] should be thrown and the internal state should be set to invalid\r\n1. If the tag is invalid on finish for decrypt it should be an exception thrown\r\n1. Once finished is called, a call to anything other than one of the Init methods will throw\r\n1. Once Init is called, a second call without \"finishing\" will throw\r\n1. If the type expects an key supplied (a straight \"new'd\" up instance) if the Initial \"Init\" call only has an IV it will throw\r\n1. If the type was generated say from a store based key and you attempt to change the key via Init and not just the IV it will throw\r\n1. If get tag is not called before dispose or Init should an exception be thrown? To stop the user not collecting the tag by accident?\r\n\r\nReference #7023 \r\n\r\n# Updates\r\n1. Changed nonce to IV.\r\n1. Added behaviour section\r\n1. Removed the single input/output span cases from finish and update, they can just be extension methods\r\n1. Changed a number of spans to readonlyspan as suggested by @bartonjs \r\n1. Removed Reset, Init with IV should be used instead"},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/327643109","html_url":"https://github.com/dotnet/corefx/issues/23629#issuecomment-327643109","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/23629","id":327643109,"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},"created_at":"2017-09-06T23:51:58Z","updated_at":"2017-09-06T23:51:58Z","author_association":"COLLABORATOR","body":"Also I am no crypto expert but doesn't AES require an IV (Which isn't a nonce but needs to be provided by the user?)"}}
{"actor":{"display_login":"Drawaes"}}