Two thoughts on this - first up, try the apple-cdsa mailing list if
all else fails; the Security guys hang out there and very often
provide exemplary assistance.
Second, I have similar code that works perfectly well, and is very
well tested... the only difference I can see, given the small snippet
you posted to the list, is that I clear the data & length fields of
each attribute before passing them into the call... it makes no sense
given the error code you're seeing, but hey, give it a shot and see
if that's it.
Failing that, 99% of the Security framework's source is available
from Apple's website, so you can peruse through it and figure out
where (and thus why) it's failing.