<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments for iOS 6 Programming: Pushing the limits</title>
	<atom:link href="http://iosptl.com/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://iosptl.com</link>
	<description>Developing Extraordinary Mobile Apps for Apple iPhone, iPad, and iPod Touch</description>
	<lastBuildDate>Fri, 25 Jan 2013 23:13:33 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
	<item>
		<title>Comment on CGLayer no longer recommended by Mariano</title>
		<link>http://iosptl.com/posts/cglayer-no-longer-recommended/#comment-99</link>
		<dc:creator>Mariano</dc:creator>
		<pubDate>Fri, 25 Jan 2013 23:13:33 +0000</pubDate>
		<guid isPermaLink="false">http://iosptl.com/?p=114#comment-99</guid>
		<description><![CDATA[I have watched it as well and I found myself frustrated at this moment because the source code is not available. Any luck on your side?]]></description>
		<content:encoded><![CDATA[<p>I have watched it as well and I found myself frustrated at this moment because the source code is not available. Any luck on your side?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on CGLayer no longer recommended by Danilo</title>
		<link>http://iosptl.com/posts/cglayer-no-longer-recommended/#comment-98</link>
		<dc:creator>Danilo</dc:creator>
		<pubDate>Thu, 17 Jan 2013 05:49:25 +0000</pubDate>
		<guid isPermaLink="false">http://iosptl.com/?p=114#comment-98</guid>
		<description><![CDATA[I have watched the 506 session videos from wwdc and also have download the source demos for the 2012 wwdc. But The code for the paint app from that session was not available. Does anyone have the source code for that app &quot;iOS Paint&quot; from the session? Thanks.]]></description>
		<content:encoded><![CDATA[<p>I have watched the 506 session videos from wwdc and also have download the source demos for the 2012 wwdc. But The code for the paint app from that session was not available. Does anyone have the source code for that app &#8220;iOS Paint&#8221; from the session? Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on The Singleton pattern by Dave</title>
		<link>http://iosptl.com/posts/the-singleton-pattern/#comment-94</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Sat, 05 Jan 2013 20:19:59 +0000</pubDate>
		<guid isPermaLink="false">http://iosptl.com/?p=90#comment-94</guid>
		<description><![CDATA[Thanks, this helps a lot!]]></description>
		<content:encoded><![CDATA[<p>Thanks, this helps a lot!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on The Singleton pattern by robnapier</title>
		<link>http://iosptl.com/posts/the-singleton-pattern/#comment-90</link>
		<dc:creator>robnapier</dc:creator>
		<pubDate>Sun, 30 Dec 2012 20:39:41 +0000</pubDate>
		<guid isPermaLink="false">http://iosptl.com/?p=90#comment-90</guid>
		<description><![CDATA[First, you need to understand the &quot;static&quot; keyword. It means that there is only one &quot;once&quot; variable.  It is not a local variable to this function, or an instance variable. There is one copy for the entire program. Furthermore, &quot;once&quot; is initialized to all zeros before the program starts running. Both of these are features of C. There&#039;s nothing special here. So no matter how we get to this method, and no matter what thread we&#039;re running on, &quot;once&quot; refers to the same memory.

dispatch_once does effectively the following:

&lt;code&gt;&lt;pre&gt;
lock(token);
if (! token) {
  ... do the block ...
  token = &lt;something not 0&gt;;
}
unlock(token);
&lt;/pre&gt;&lt;/code&gt;

Logically it works like the above, but the actual implementations of &quot;lock()&quot; and &quot;unlock()&quot; are insanely fast if token has already been set and there&#039;s no actual blocking. See &lt;a href=&quot;http://alanquatermain.me/post/114613488/lockless-lazily-initialized-static-global-variables&quot; rel=&quot;nofollow&quot;&gt;Jim Dovey&#039;s discussion&lt;/a&gt; on how this can be implemented using OSAtomicCompareAndSwapPtrBarrier(), which is probably similar to how dispatch_once is actually implemented, but I haven&#039;t gone and looked.]]></description>
		<content:encoded><![CDATA[<p>First, you need to understand the &#8220;static&#8221; keyword. It means that there is only one &#8220;once&#8221; variable.  It is not a local variable to this function, or an instance variable. There is one copy for the entire program. Furthermore, &#8220;once&#8221; is initialized to all zeros before the program starts running. Both of these are features of C. There&#8217;s nothing special here. So no matter how we get to this method, and no matter what thread we&#8217;re running on, &#8220;once&#8221; refers to the same memory.</p>
<p>dispatch_once does effectively the following:</p>
<p><code>
<pre>
lock(token);
if (! token) {
  ... do the block ...
  token = &lt;something not 0&gt;;
}
unlock(token);
</pre>
<p></code></p>
<p>Logically it works like the above, but the actual implementations of &#8220;lock()&#8221; and &#8220;unlock()&#8221; are insanely fast if token has already been set and there&#8217;s no actual blocking. See <a href="http://alanquatermain.me/post/114613488/lockless-lazily-initialized-static-global-variables" rel="nofollow">Jim Dovey&#8217;s discussion</a> on how this can be implemented using OSAtomicCompareAndSwapPtrBarrier(), which is probably similar to how dispatch_once is actually implemented, but I haven&#8217;t gone and looked.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on The Singleton pattern by Dave</title>
		<link>http://iosptl.com/posts/the-singleton-pattern/#comment-89</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Sun, 30 Dec 2012 20:04:59 +0000</pubDate>
		<guid isPermaLink="false">http://iosptl.com/?p=90#comment-89</guid>
		<description><![CDATA[I am working my way through your iOS6 book.  For someone not very experienced with GCD Could you explain the syntax for this singleton pattern?  thanks.]]></description>
		<content:encoded><![CDATA[<p>I am working my way through your iOS6 book.  For someone not very experienced with GCD Could you explain the syntax for this singleton pattern?  thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on CGLayer no longer recommended by Akiel</title>
		<link>http://iosptl.com/posts/cglayer-no-longer-recommended/#comment-75</link>
		<dc:creator>Akiel</dc:creator>
		<pubDate>Wed, 21 Nov 2012 16:35:18 +0000</pubDate>
		<guid isPermaLink="false">http://iosptl.com/?p=114#comment-75</guid>
		<description><![CDATA[Answering my own question after looking at CALayer header which says
@property(retain) id contents;
so the answer is yes (should&#039;ve checked before asking, sorry!)]]></description>
		<content:encoded><![CDATA[<p>Answering my own question after looking at CALayer header which says<br />
@property(retain) id contents;<br />
so the answer is yes (should&#8217;ve checked before asking, sorry!)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on CGLayer no longer recommended by Akiel</title>
		<link>http://iosptl.com/posts/cglayer-no-longer-recommended/#comment-74</link>
		<dc:creator>Akiel</dc:creator>
		<pubDate>Wed, 21 Nov 2012 16:24:45 +0000</pubDate>
		<guid isPermaLink="false">http://iosptl.com/?p=114#comment-74</guid>
		<description><![CDATA[Rob,

Would I be right in assuming that multiple instances of CALayer can share the same content? In the sense that when you set

layer1.content = aCGImage;
layer2.content = aCGImage;

they&#039;re pointing to the same CGImage in memory, as opposed to each layer making its own copy of the image? 

I had an app in mind that would make extensive use of &quot;stamping&quot;, as you call it.]]></description>
		<content:encoded><![CDATA[<p>Rob,</p>
<p>Would I be right in assuming that multiple instances of CALayer can share the same content? In the sense that when you set</p>
<p>layer1.content = aCGImage;<br />
layer2.content = aCGImage;</p>
<p>they&#8217;re pointing to the same CGImage in memory, as opposed to each layer making its own copy of the image? </p>
<p>I had an app in mind that would make extensive use of &#8220;stamping&#8221;, as you call it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Going Offline Errata by Alice</title>
		<link>http://iosptl.com/posts/going-offline-errata/#comment-73</link>
		<dc:creator>Alice</dc:creator>
		<pubDate>Sun, 11 Nov 2012 13:05:05 +0000</pubDate>
		<guid isPermaLink="false">http://iosptl.com/?p=96#comment-73</guid>
		<description><![CDATA[Hi!
In method isMenuItemsStale, the stalenessLevel is always returned negative.
This is because the file modification date is always earlier than current date.
I modified it to:
NSDate *now = [NSDate date];
NSDate *modificationDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:archivePath error:nil] fileModificationDate];
NSTimeInterval stalenessLevel = [now timeIntervalSinceDate:modificationDate];

Does it make sense?]]></description>
		<content:encoded><![CDATA[<p>Hi!<br />
In method isMenuItemsStale, the stalenessLevel is always returned negative.<br />
This is because the file modification date is always earlier than current date.<br />
I modified it to:<br />
NSDate *now = [NSDate date];<br />
NSDate *modificationDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:archivePath error:nil] fileModificationDate];<br />
NSTimeInterval stalenessLevel = [now timeIntervalSinceDate:modificationDate];</p>
<p>Does it make sense?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Going Offline Errata by Jose</title>
		<link>http://iosptl.com/posts/going-offline-errata/#comment-60</link>
		<dc:creator>Jose</dc:creator>
		<pubDate>Mon, 01 Oct 2012 09:25:58 +0000</pubDate>
		<guid isPermaLink="false">http://iosptl.com/?p=96#comment-60</guid>
		<description><![CDATA[Also I think on method:
+ (void)cacheData:(NSData*) data toFile:(NSString*) fileName;

The part:

&lt;code&gt; 
if ([recentlyAccessedKeys count] &gt; kCacheMemoryLimit) {
   NSString *leastRecentlyUsedDataFilename = [recentlyAccessedKeys lastObject];
   NSData *leastRecentlyUsedCacheData = [memoryCache objectForKey:leastRecentlyUsedDataFilename];
   NSString *archivePath = [[AppCache cacheDirectory] stringByAppendingPathComponent:fileName];  
   [leastRecentlyUsedCacheData writeToFile:archivePath atomically:YES];
    
   [recentlyAccessedKeys removeLastObject];
   [memoryCache removeObjectForKey:leastRecentlyUsedDataFilename];
}
&lt;/code&gt;

Should be: 

&lt;code&gt; 
if ([recentlyAccessedKeys count] &gt; kCacheMemoryLimit) {
   NSString *leastRecentlyUsedDataFilename = [recentlyAccessedKeys lastObject];
   NSData *leastRecentlyUsedCacheData = [memoryCache objectForKey:leastRecentlyUsedDataFilename];
   // Changes: path yo save in disk the last object in memory
   NSString *archivePath = [[AppCache cacheDirectory] stringByAppendingPathComponent:leastRecentlyUsedDataFilename];  
   // End changes.
   [leastRecentlyUsedCacheData writeToFile:archivePath atomically:YES];
    
   [recentlyAccessedKeys removeLastObject];
   [memoryCache removeObjectForKey:leastRecentlyUsedDataFilename];
}
&lt;/code&gt;


Thanks!
Jose.]]></description>
		<content:encoded><![CDATA[<p>Also I think on method:<br />
+ (void)cacheData:(NSData*) data toFile:(NSString*) fileName;</p>
<p>The part:</p>
<p><code><br />
if ([recentlyAccessedKeys count] &gt; kCacheMemoryLimit) {<br />
   NSString *leastRecentlyUsedDataFilename = [recentlyAccessedKeys lastObject];<br />
   NSData *leastRecentlyUsedCacheData = [memoryCache objectForKey:leastRecentlyUsedDataFilename];<br />
   NSString *archivePath = [[AppCache cacheDirectory] stringByAppendingPathComponent:fileName];<br />
   [leastRecentlyUsedCacheData writeToFile:archivePath atomically:YES];</p>
<p>   [recentlyAccessedKeys removeLastObject];<br />
   [memoryCache removeObjectForKey:leastRecentlyUsedDataFilename];<br />
}<br />
</code></p>
<p>Should be: </p>
<p><code><br />
if ([recentlyAccessedKeys count] &gt; kCacheMemoryLimit) {<br />
   NSString *leastRecentlyUsedDataFilename = [recentlyAccessedKeys lastObject];<br />
   NSData *leastRecentlyUsedCacheData = [memoryCache objectForKey:leastRecentlyUsedDataFilename];<br />
   // Changes: path yo save in disk the last object in memory<br />
   NSString *archivePath = [[AppCache cacheDirectory] stringByAppendingPathComponent:leastRecentlyUsedDataFilename];<br />
   // End changes.<br />
   [leastRecentlyUsedCacheData writeToFile:archivePath atomically:YES];</p>
<p>   [recentlyAccessedKeys removeLastObject];<br />
   [memoryCache removeObjectForKey:leastRecentlyUsedDataFilename];<br />
}<br />
</code></p>
<p>Thanks!<br />
Jose.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on &#8220;New&#8221; (well, not really new) PRF functions for PBKDF2 by robnapier</title>
		<link>http://iosptl.com/posts/new-prf-functions-for-pbkdf2/#comment-44</link>
		<dc:creator>robnapier</dc:creator>
		<pubDate>Wed, 19 Sep 2012 02:06:29 +0000</pubDate>
		<guid isPermaLink="false">http://iosptl.com/?p=204#comment-44</guid>
		<description><![CDATA[I used to write Infosec policy for Cisco, and performed security assessments for them for years. While I&#039;ve learned a lot more of the theory in recent years, I&#039;ve always been focused on the practical aspects of security. You are correct that as a matter of corporate policy it is convenient to make blanket statements like &quot;never use SHA-1.&quot; But it is critical that we as security engineers know the details, even if we write more conservative policy. Otherwise we undermine our credibility fighting over something that isn&#039;t actually a risk.

I&#039;m aware of no security risks in using SHA-1 in the HMAC of PBKDF2 that are mitigated by using SHA-2. I am eager for links to known or theorized vulnerabilities from knowledgeable writers. It&#039;s not just that it&#039;s &quot;not that bad.&quot; It is currently equivalent to SHA-2 in security terms for use within the HMAC of PBKDF2. PBKDF2 simply does not require a collision-resistant hash in its HMAC in order to maintain its security (hooray!). This is why Schneier said &lt;a href-&quot;http://www.schneier.com/blog/archives/2005/02/sha1_broken.html&quot; rel=&quot;nofollow&quot;&gt;&quot;it doesn&#039;t affect applications such as HMAC where collisions aren&#039;t important.&quot;&lt;/a&gt; There are some concerns about PBKDF2 because its may be too easy to implement in hardware, but that&#039;s unrelated to collisions in the hash function and is not improved with SHA-2.

I developed RNCryptor specifically because so many iOS developers were using AES wrong. They&#039;d heard the simple rule &quot;AES good,&quot; and then proceeded to implement it completely insecurely thinking that its AESness would cover all sins. We need to educate our engineers better in how crypto systems work and how to reason about them. There is too much &quot;I heard this was good and this was bad&quot; and it leads to bad security implementations. Someone in the org needs to know how to evaluate issues with more than just rules of thumb, and developers need know when to go to the expert for advice.

Of course you shouldn&#039;t design your own KDF. No argument. Nor your own hash or cipher. You shouldn&#039;t even implement them yourself if you can possibly help it. That&#039;s why RNCryptor relies entirely on the OS for security code.

As I said, we should move to SHA-2 in PBKDF2 as a matter of housekeeping. We should move to SHA-2 for digests as a matter of security. Security people should be clear on the difference, and push much harder on the ones that matter so we don&#039;t use too much political capital fixing things that aren&#039;t broken.

I apologize for the length. I&#039;ve tried to trim it down a bit. This is a passion for me, as I suspect it is for you. And I still highly recommend the &lt;a href=&quot;http://cryptoclass.org&quot; rel=&quot;nofollow&quot;&gt;Stanford course&lt;/a&gt;. It&#039;s free and excellent. I think every senior security professional should at least attempt it.

Thanks for reading. I do appreciate the comments. As you say, this stuff is very real-world for you. I hope my writing can help your iOS developers write more secure code.]]></description>
		<content:encoded><![CDATA[<p>I used to write Infosec policy for Cisco, and performed security assessments for them for years. While I&#8217;ve learned a lot more of the theory in recent years, I&#8217;ve always been focused on the practical aspects of security. You are correct that as a matter of corporate policy it is convenient to make blanket statements like &#8220;never use SHA-1.&#8221; But it is critical that we as security engineers know the details, even if we write more conservative policy. Otherwise we undermine our credibility fighting over something that isn&#8217;t actually a risk.</p>
<p>I&#8217;m aware of no security risks in using SHA-1 in the HMAC of PBKDF2 that are mitigated by using SHA-2. I am eager for links to known or theorized vulnerabilities from knowledgeable writers. It&#8217;s not just that it&#8217;s &#8220;not that bad.&#8221; It is currently equivalent to SHA-2 in security terms for use within the HMAC of PBKDF2. PBKDF2 simply does not require a collision-resistant hash in its HMAC in order to maintain its security (hooray!). This is why Schneier said <a href-"http://www.schneier.com/blog/archives/2005/02/sha1_broken.html" rel="nofollow">&#8220;it doesn&#8217;t affect applications such as HMAC where collisions aren&#8217;t important.&#8221;</a> There are some concerns about PBKDF2 because its may be too easy to implement in hardware, but that&#8217;s unrelated to collisions in the hash function and is not improved with SHA-2.</p>
<p>I developed RNCryptor specifically because so many iOS developers were using AES wrong. They&#8217;d heard the simple rule &#8220;AES good,&#8221; and then proceeded to implement it completely insecurely thinking that its AESness would cover all sins. We need to educate our engineers better in how crypto systems work and how to reason about them. There is too much &#8220;I heard this was good and this was bad&#8221; and it leads to bad security implementations. Someone in the org needs to know how to evaluate issues with more than just rules of thumb, and developers need know when to go to the expert for advice.</p>
<p>Of course you shouldn&#8217;t design your own KDF. No argument. Nor your own hash or cipher. You shouldn&#8217;t even implement them yourself if you can possibly help it. That&#8217;s why RNCryptor relies entirely on the OS for security code.</p>
<p>As I said, we should move to SHA-2 in PBKDF2 as a matter of housekeeping. We should move to SHA-2 for digests as a matter of security. Security people should be clear on the difference, and push much harder on the ones that matter so we don&#8217;t use too much political capital fixing things that aren&#8217;t broken.</p>
<p>I apologize for the length. I&#8217;ve tried to trim it down a bit. This is a passion for me, as I suspect it is for you. And I still highly recommend the <a href="http://cryptoclass.org" rel="nofollow">Stanford course</a>. It&#8217;s free and excellent. I think every senior security professional should at least attempt it.</p>
<p>Thanks for reading. I do appreciate the comments. As you say, this stuff is very real-world for you. I hope my writing can help your iOS developers write more secure code.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
