{"id":44173,"date":"2015-04-23T07:00:00","date_gmt":"2015-04-23T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2015\/04\/23\/how-did-the-scopes-for-the-cryptprotectmemory-function-end-up-in-a-strange-order\/"},"modified":"2019-03-13T12:14:59","modified_gmt":"2019-03-13T19:14:59","slug":"20150423-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20150423-00\/?p=44173","title":{"rendered":"How did the scopes for the CryptProtectMemory function end up in a strange order?"},"content":{"rendered":"<p>A few weeks ago, I left an exercise: <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2015\/04\/13\/10607036.aspx\">Propose a theory as to why the names and values of the scopes for the <code>Crypt&shy;Protect&shy;Memory<\/code> function are the way they are<\/a>. <\/p>\n<p>I didn&#8217;t know the answer when I posed the exercise, but I went back and dug into it. <\/p>\n<p>The <code>Crypt&shy;Protect&shy;Memory<\/code> function started out as an internal function back in Windows 2000, and when originally introduced, there were only two scopes: Within a process and cross-process. The Flags parameter therefore defined only a single bit, leaving the other bits reserved (must be zero). If the bottom bit was clear, then the memory was protected within a process; if the bottom bit was set, then the memory was protected across processes. <\/p>\n<p>Later, the team realized that they needed to add a third scope, the one that corresponds to <code>CRYPT&shy;PROTECT_SAME_LOGON<\/code>. They didn&#8217;t want to make a breaking change for existing callers, but they saw that they could retarget what used to be a Flags parameter as an Options parameter, and they added the new scope as a third option. <\/p>\n<p>The numeric values remained unchanged, which meant that the new function was backward-compatible with existing callers. <\/p>\n<p><b>Bonus chatter<\/b>: Commenter sense is correct that <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2015\/04\/13\/10607036.aspx#10607280\"><code>SAME_LOGON<\/code> can be used by a service while impersonating the client<\/a>, however it is not the case that the scope can be larger when impersonating a remote user. The memory block returned by the <code>Crypt&shy;Protect&shy;Memory<\/code> function can be decrypted only on the same machine that encrypted it, and only as long as the machine has not been rebooted. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Incremental functionality.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2],"class_list":["post-44173","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history"],"acf":[],"blog_post_summary":"<p>Incremental functionality.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/44173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=44173"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/44173\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=44173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=44173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=44173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}