Crypt::AppleTwoFish -- two Apple iTMS/iTunes key descrambling algorithms
The first algorithm appears to have only cursory resemblance to Bruce Schneier's blowfish and twofish algorithms in that it too has a table-based decoder.
The second algorithm is more standard encryption using S-box type permutations and lookup tables, and might have started out something like Twofish or Blowfish.
for iTMS usages: use Crypt::AppleTwoFish; my $scrambled_key = '=sixteen uchars='; my $apple_twofish = new Crypt::AppleTwoFish(key => $scrambled_key); my $descrambled_key = $apple_twofish->decrypted_for_iTMS; my $descrambled_another_way = $apple_twofish->decrypted_for_DRMS; ..and for iTunes 7 compatible usages: Functions cloned from lower level compiled code which was likely intended to be difficult to reconstruct cannot easily be given sensible names. Ada Pro is good, but dull. We chose to be amused during the tedium by coming up with function names from a vegetable farm. For actual usage, see also:
Call with the key as a scalar argument. When passed (LWP simulating iTunes) over iTMS, encrypted M4P keys for your purchased music are currently 16 unsigned chars in length.
Returns the unscrambled key for use with the Apple Music Store.
Returns the unscrambled key for use with iTunes/iPod DRM.
Get/set initial key.
Get/set veggie integer table.
Get/set veggie byte table.
Get/set hardware ID (MAC address or other machine based data). 6 bytes.
Get/set key ID. 4 bytes.
Get/set user ID. 4 bytes.
Key munging, spring season
Key munging, harvest season
iTMS decrambler adapted from FairKeys 0.5, by Jon Lech Johansen, and from the alterate scramble table found by FutureProof. Veggie Tales algorithm courtesy of Ada and other anonymous pros :-).
Questions, feature requests and bug reports should go to <email@example.com>.
Copyright (c) 2005, 2008 William Herrera. All rights reserved. Licensing Terms a) The terms of Perl itself, plus the following: b) UNDER NO CIRCUMSTANCES CAN THIS CODE BE USED FOR CIRCUMVENTION OF ANY TECHNOLOGICAL MEASURE WHICH EFFECTIVELY CONTROLS A PROTECTED MEDIA WORK UNDER THE DCMA (USA, 1998) OR EU COPYRIGHT DIRECTIVE (EUCD, ARTICLE 6, OF 2001), UNDER ANY OPERATING SYSTEM PLATFORM SUPPORTED BY APPLE COMPUTER CORPORATION FOR ITS ITUNES OR IPOD PLAYER SOFTWARE IN ANY APPLE CORPORATION DISTRIBUTED BINARY FORMAT OF ITUNES FOR THE PLATFORM UNDER WHICH THAT MEDIA IS TO BE PLAYED. AS OF 2008, PROHIBITED PLATFORMS INCLUDE THE IPOD, IPHONE, APPLE OS X, AND MICROSOFT WINDOWS, BUT NOT LINUX, BSD, OR SOLARIS. UNDER NO CIRCUMSTANCES CAN THE AUTHOR(S) OF THIS CODE BE HELD LIABLE FOR ANY INFRINGEMENT INVOLVING THE PROHIBITED PLATFORMS ABOVE. c) Use, storage, or distribution of this code implies that you accept that its intended purpose is legal and legitimate under any applicable US or EU law, as above, and agree that any and all risk as to the quality, performance, and legality of this code lies with you.