<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.theiphonewiki.com/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Him121213</id>
	<title>The iPhone Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.theiphonewiki.com/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Him121213"/>
	<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/wiki/Special:Contributions/Him121213"/>
	<updated>2026-06-06T12:34:15Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.14</generator>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=KBAG&amp;diff=3727</id>
		<title>KBAG</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=KBAG&amp;diff=3727"/>
		<updated>2009-05-20T03:37:51Z</updated>

		<summary type="html">&lt;p&gt;Him121213: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Explanation==&lt;br /&gt;
In Apple's new IMG3 security scheme, they have used something called a KBAG. At the bottom of a firmware file, you will see something that will, on the ASCII side of your hex editor, see &amp;quot;GABK&amp;quot;, which is &amp;quot;KBAG&amp;quot; flipped. Look on the hex side and you will the KBAG according to this format:&lt;br /&gt;
&lt;br /&gt;
==KBAG Format==&lt;br /&gt;
===KBAG128===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
typedef struct Unparsed_KBAG_128 {&lt;br /&gt;
     char[4]           magic;          // string with bits flipped = &amp;quot;KBAG&amp;quot; (magic = 0x4741424B)&lt;br /&gt;
     int         tagFullSize;          // size of KBAG from beyond that point to the end of it&lt;br /&gt;
     int         tagDataSize;          // size of just the tag info, not this 0xC &amp;quot;header&amp;quot;&lt;br /&gt;
     int  IV_Key_Crypt_state;          // 1 if the key and IV in the KBAG are encrypted with the GID key, 0 if not.&lt;br /&gt;
     int            AES_Type;          // 0x80 = aes128 / 0xc0 = aes192 / 0x100 = aes256&lt;br /&gt;
     char[16]         Enc_IV;          // IV for the firmware file, encrypted with the gid key&lt;br /&gt;
     char[16]        Enc_Key;          // Key for the firmware file, encrypted with the gid key.&lt;br /&gt;
} Unparsed_KBAG_AES128;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===KBAG192===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
typedef struct Unparsed_KBAG_AES192 {&lt;br /&gt;
     char[4]           magic;          // string with bits flipped = &amp;quot;KBAG&amp;quot; (magic = 0x4741424B)&lt;br /&gt;
     int            fullSize;          // size of KBAG from beyond that point to the end of it&lt;br /&gt;
     int                unk1;          // 8 less than fullSize. not sure what it is exactly.&lt;br /&gt;
     int  IV_Key_Crypt_state;          // 1 if the key and IV in the KBAG are encrypted with the GID key, 0 if not.&lt;br /&gt;
     int            AES_Type;          // 0x80 = aes128 / 0xc0 = aes192 / 0x100 = aes256&lt;br /&gt;
     char[16]         Enc_IV;          // IV for the firmware file, encrypted with the gid key&lt;br /&gt;
     char[24]        Enc_Key;          // Key for the firmware file, encrypted with the gid key.&lt;br /&gt;
} Unparsed_KBAG_AES192;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===KBAG256===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
typedef struct Unparsed_KBAG_256 {&lt;br /&gt;
     char[4]           magic;          // string with bits flipped = &amp;quot;KBAG&amp;quot; (magic = 0x4741424B)&lt;br /&gt;
     int            fullSize;          // size of KBAG from beyond that point to the end of it&lt;br /&gt;
     int                unk1;          // 8 less than fullSize. not sure what it is exactly.&lt;br /&gt;
     int  IV_Key_Crypt_state;          // 1 if the key and IV in the KBAG are encrypted with the GID key, 0 if not.&lt;br /&gt;
     int            AES_Type;          // 0x80 = aes-128, 0xc0 = aes-192, 0x100 = aes256&lt;br /&gt;
     char[16]         Enc_IV;          // IV for the firmware file, encrypted with the gid key&lt;br /&gt;
     char[32]        Enc_Key;          // Key for the firmware file, encrypted with the gid key.&lt;br /&gt;
} Unparsed_KBAG_AES256;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
Basically, it just boils down to using the iPhone / iPod group id key to decrypt Enc_IV and Enc_Key, then using that key and IV to decrypt the DATA section of the file (the code itself).&lt;br /&gt;
&lt;br /&gt;
As an interesting side note, because of the circumstances with the [[IMG3]] format, the Kernel never needs to even touch the gid key anymore, as it's job is to just flash the image to the [[NOR]] as is, with container and all.&lt;/div&gt;</summary>
		<author><name>Him121213</name></author>
		
	</entry>
</feed>